PHP Класс Webiny\Component\Cache\CacheStorage

The best way to create a CacheStorage instance is over the Cache class.
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__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.

Описание методов

__construct() публичный Метод

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() публичный Метод

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
Результат boolean

add() публичный Метод

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.
Результат boolean True if value was added, otherwise false.

delete() публичный Метод

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.
Результат boolean | array If array of keys was passed, on error will be returned array of not deleted keys, or true on success.

deleteByTags() публичный Метод

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.
Результат boolean

deleteOld() публичный Метод

Delete expired cache values.
public deleteOld ( ) : boolean
Результат boolean

getDriver() публичный Метод

Get driver instance.
public getDriver ( ) : Webiny\Component\Cache\Bridge\CacheStorageInterface
Результат Webiny\Component\Cache\Bridge\CacheStorageInterface

getStatus() публичный Метод

Get cache status.
public getStatus ( ) : mixed
Результат mixed

getTtl() публичный Метод

Returns the ttl from options.
public getTtl ( ) : integer
Результат integer

increment() публичный Метод

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.
Результат integer | string | array New key value.

lockKey() публичный Метод

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
Результат boolean

read() публичный Метод

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.
Результат mixed

save() публичный Метод

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.
Результат boolean True if value was stored successfully, otherwise false.

selectByCallback() публичный Метод

Only values of array type will be selected.
public selectByCallback ( callable $callback, boolean $getArray = false ) : mixed
$callback callable ($value_array,$key)
$getArray boolean
Результат mixed

setStatus() публичный Метод

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