PHP Class Webiny\Component\Cache\CacheStorage

The best way to create a CacheStorage instance is over the Cache class.
显示文件 Open project: Webiny/Framework Class Usage Examples

Public Methods

Method Description
__construct ( Webiny\Component\Cache\Bridge\CacheStorageInterface $driver, array $options = [] ) Create a cache driver instance.
acquireKey ( string $key, &$autoUnlocker ) : boolean Try to lock key, and if key is already locked - wait, until key will be unlocked.
add ( string $key, mixed $value, integer $ttl = null, array | string $tags = null ) : boolean Save a value into memory only if it DOESN'T exists (or false will be returned).
delete ( string | array $key ) : boolean | array Delete key or array of keys from storage.
deleteByTags ( array | string $tag ) : boolean Delete keys by tags.
deleteOld ( ) : boolean Delete expired cache values.
getDriver ( ) : Webiny\Component\Cache\Bridge\CacheStorageInterface Get driver instance.
getStatus ( ) : mixed Get cache status.
getTtl ( ) : integer Returns the ttl from options.
increment ( string $key, mixed $byValue = 1, integer $limitKeysCount, integer $ttl = 259200 ) : integer | string | array Increment value of the key.
lockKey ( mixed $key, mixed &$autoUnlockerVariable ) : boolean Get exclusive mutex for key. Key will be still accessible to read and write, but another process can exclude dog-pile effect, if before updating the key he will try to get this mutex.
read ( string | array $key, mixed &$ttlLeft ) : mixed Get the cache data for the given $key.
save ( string $key, mixed $value, integer $ttl = null, array | string $tags = null ) : boolean Save a value into memory.
selectByCallback ( callable $callback, boolean $getArray = false ) : mixed Select from storage via callback function.
setStatus ( boolean $status ) Change the cache status.

Method Details

__construct() public method

Create a cache driver instance.
public __construct ( Webiny\Component\Cache\Bridge\CacheStorageInterface $driver, array $options = [] )
$driver Webiny\Component\Cache\Bridge\CacheStorageInterface Instance of CacheInterface.
$options array Array of options.

acquireKey() public method

Time of waiting is defined in max_wait_unlock constant of MemoryObject class.
public acquireKey ( string $key, &$autoUnlocker ) : boolean
$key string Name of the cache key.
$autoUnlocker
return boolean

add() public method

Save a value into memory only if it DOESN'T exists (or false will be returned).
public add ( string $key, mixed $value, integer $ttl = null, array | string $tags = null ) : boolean
$key string Name of the key.
$value mixed Value you wish to save.
$ttl integer For how long to store value. (in seconds)
$tags array | string Tags you wish to assign to this cache entry.
return boolean True if value was added, otherwise false.

delete() public method

Delete key or array of keys from storage.
public delete ( string | array $key ) : boolean | array
$key string | array Key, or array of keys, you wish to delete.
return boolean | array If array of keys was passed, on error will be returned array of not deleted keys, or true on success.

deleteByTags() public method

Delete keys by tags.
public deleteByTags ( array | string $tag ) : boolean
$tag array | string Tag, or an array of tags, for which you wish to delete the cache.
return boolean

deleteOld() public method

Delete expired cache values.
public deleteOld ( ) : boolean
return boolean

getDriver() public method

Get driver instance.
public getDriver ( ) : Webiny\Component\Cache\Bridge\CacheStorageInterface
return Webiny\Component\Cache\Bridge\CacheStorageInterface

getStatus() public method

Get cache status.
public getStatus ( ) : mixed
return mixed

getTtl() public method

Returns the ttl from options.
public getTtl ( ) : integer
return integer

increment() public method

Increment value of the key.
public increment ( string $key, mixed $byValue = 1, integer $limitKeysCount, integer $ttl = 259200 ) : integer | string | array
$key string Name of the cache key.
$byValue mixed If stored value is an array: - If $by_value is a value in array, new element will be pushed to the end of array, - If $by_value is a key=>value array, new key=>value pair will be added (or updated).
$limitKeysCount integer Maximum count of elements (used only if stored value is array).
$ttl integer Set time to live for key.
return integer | string | array New key value.

lockKey() public method

Get exclusive mutex for key. Key will be still accessible to read and write, but another process can exclude dog-pile effect, if before updating the key he will try to get this mutex.
public lockKey ( mixed $key, mixed &$autoUnlockerVariable ) : boolean
$key mixed Name of the cache key.
$autoUnlockerVariable mixed Pass empty, just declared variable
return boolean

read() public method

Get the cache data for the given $key.
public read ( string | array $key, mixed &$ttlLeft ) : mixed
$key string | array Name of the cache key.
$ttlLeft mixed = (ttl - time()) of key. Use to exclude dog-pile effect, with lock/unlock_key methods.
return mixed

save() public method

Save a value into memory.
public save ( string $key, mixed $value, integer $ttl = null, array | string $tags = null ) : boolean
$key string Name of the key.
$value mixed Value you wish to save.
$ttl integer For how long to store value. (in seconds)
$tags array | string Tags you wish to assign to this cache entry.
return boolean True if value was stored successfully, otherwise false.

selectByCallback() public method

Only values of array type will be selected.
public selectByCallback ( callable $callback, boolean $getArray = false ) : mixed
$callback callable ($value_array,$key)
$getArray boolean
return mixed

setStatus() public method

Change the cache status.
public setStatus ( boolean $status )
$status boolean Turn caching on or off.