PHP Trait luya\traits\CacheableTrait

Concret implementation example: $cacheKey = 'foobar'; $cache = $this->getHasCache($cacheKey); if ($cache === false) { execute code and save cache data into variable $this->setHasCache($cacheKey, $cache); // variable $cache has been changed from above } return $cache;
Since: 1.0.0-beta4
Author: nadar
Datei anzeigen Open project: luyadev/luya

Public Properties

Property Type Description
$cacheEnabled If enabled and the cache component is available. If disabled it will fully ignore the any caching but does not throw exception.
$cacheExpiration Defined the duration of the caching lifetime in seconds. 3600 = 1 hour, 86400 = 24 hours. 0 is forever

Public Methods

Method Description
deleteHasCache ( string | array $key ) : boolean Remove a value from the cache if caching is enabled.
getHasCache ( string | array $key ) : mixed | boolean Get the caching data if caching is allowed and there is any data stored for this key.
isCachable ( ) : boolean Check if the current configuration of the application and the property allows a caching of the language container data.
setHasCache ( string | array $key, mixed $value, yii\caching\Dependency | array $dependency = null, $cacheExpiration = null ) : boolean Store cache data for a specific key if caching is enabled in this application.

Method Details

deleteHasCache() public method

Remove a value from the cache if caching is enabled.
public deleteHasCache ( string | array $key ) : boolean
$key string | array The cache identifier
return boolean Whether delete of key has been success or not

getHasCache() public method

Get the caching data if caching is allowed and there is any data stored for this key.
public getHasCache ( string | array $key ) : mixed | boolean
$key string | array The identifiere key, can be a string or an array which will be calculated.
return mixed | boolean Returns the data, if not found returns false.

isCachable() public method

Check if the current configuration of the application and the property allows a caching of the language container data.
public isCachable ( ) : boolean
return boolean

setHasCache() public method

Store cache data for a specific key if caching is enabled in this application.
public setHasCache ( string | array $key, mixed $value, yii\caching\Dependency | array $dependency = null, $cacheExpiration = null ) : boolean
$key string | array The identifier key or a array to store complex keys
$value mixed The value to store in the cache component.
$dependency yii\caching\Dependency | array Dependency of the cached item. If the dependency changes, the corresponding value in the cache will be invalidated when it is fetched via get(). This parameter is ignored if $serializer is false. You can also define an array with defintion which will generate the Object instead of object is provided.
return boolean Whether set has been success or not

Property Details

$cacheEnabled public_oe property

If enabled and the cache component is available. If disabled it will fully ignore the any caching but does not throw exception.
public $cacheEnabled

$cacheExpiration public_oe property

Defined the duration of the caching lifetime in seconds. 3600 = 1 hour, 86400 = 24 hours. 0 is forever
public $cacheExpiration