PHP Класс lithium\storage\cache\adapter\File

This File adapter provides basic support for write, read, delete and clear cache functionality, as well as allowing the first four methods to be filtered as per the Lithium filtering system. The File adapter is a very simple cache, and should only be used for prototyping or for specifically caching _files_. For more general caching needs, please consider using a more appropriate cache adapter. This adapter does *not* provide increment/decrement functionality. For such functionality, please use a more approrpiate cache adapter. This adapter does *not* allow multi-key operations for any methods. The path that the cached files will be written to defaults to LITHIUM_APP_PATH/resources/tmp/cache, but is user-configurable on cache configuration. Note that the cache expiration time is stored within the first few bytes of the cached data, and is transparently added and/or removed when values are stored and/or retrieved from the cache.
См. также: lithium\storage\cache\adapter
Наследование: extends lithium\core\Object
Показать файл Открыть проект Примеры использования класса

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

Метод Описание
__construct ( array $config = [] ) : void Constructor.
clean ( ) : boolean Cleans entire cache running garbage collection on it. Please note that a scope - in case one is set - is *not* honored.
clear ( ) : boolean Clears entire cache by flushing it. Please note that a scope - in case one is set - is *not* honored.
decrement ( string $key, integer $offset = 1 ) : integer | boolean Performs a decrement operation on a specified numeric cache item.
delete ( array $keys ) : boolean Will attempt to remove specified keys from the user space cache.
increment ( string $key, integer $offset = 1 ) : integer | boolean Performs an increment operation on a specified numeric cache item.
read ( array $keys ) : array Read values from the cache. Will attempt to return an array of data containing key/value pairs of the requested data.
write ( array $keys, string | integer $expiry = null ) : boolean Write values to the cache. All items to be cached will receive an expiration time of $expiry.

Защищенные методы

Метод Описание
_compile ( string $key, mixed $value, integer $expires ) : string Compiles value to format.
_delete ( string $key ) : boolean Deletes a file using the corresponding cached item key.
_parse ( string $data ) : array Parses value from format.
_read ( string $key ) : array | boolean Reads from file, parses its format and returns its expiry and value.
_write ( string $key, mixed $value, integer $expires ) : boolean Compiles value to format and writes file.

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

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

Constructor.
См. также: lithium\storage\Cache::config()
public __construct ( array $config = [] ) : void
$config array Configuration for this cache adapter. These settings are queryable through `Cache::config('name')`. The available options are as follows: - `'scope'` _string_: Scope which will prefix keys; per default not set. - `'expiry'` _mixed_: The default expiration time for cache values, if no value is otherwise set. Can be either a `strtotime()` compatible tring or TTL in seconds. To indicate items should not expire use `Cache::PERSIST`. Defaults to `+1 hour`. - `'path'` _string_: Path where cached entries live, defaults to `Libraries::get(true, 'resources') . '/tmp/cache'`.
Результат void

_compile() защищенный Метод

Compiles value to format.
protected _compile ( string $key, mixed $value, integer $expires ) : string
$key string Key to uniquely identify the cached items.
$value mixed Value to store under given key.
$expires integer UNIX timestamp after which the item is invalid.
Результат string The compiled data string.

_delete() защищенный Метод

Deletes a file using the corresponding cached item key.
См. также: lithium\storage\cache\adapter\File::delete()
protected _delete ( string $key ) : boolean
$key string Key to uniquely identify the cached item.
Результат boolean `true` on success, `false` otherwise.

_parse() защищенный Метод

Parses value from format.
protected _parse ( string $data ) : array
$data string Compiled data string.
Результат array Array with `expiry` and `value`.

_read() защищенный Метод

Reads from file, parses its format and returns its expiry and value.
См. также: lithium\storage\cache\adapter\File::read()
protected _read ( string $key ) : array | boolean
$key string Key to uniquely identify the cached item.
Результат array | boolean Array with `expiry` and `value` or `false` otherwise.

_write() защищенный Метод

Compiles value to format and writes file.
См. также: lithium\storage\cache\adapter\File::write()
protected _write ( string $key, mixed $value, integer $expires ) : boolean
$key string Key to uniquely identify the cached item.
$value mixed Value to store under given key.
$expires integer UNIX timestamp after which the item is invalid.
Результат boolean `true` on success, `false` otherwise.

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

The operation will continue to remove keys even if removing one single key fails, cleaning thoroughly as possible.
public clean ( ) : boolean
Результат boolean `true` on successful cleaning, `false` if failed partially or entirely.

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

The operation will continue to remove keys even if removing one single key fails, clearing thoroughly as possible.
public clear ( ) : boolean
Результат boolean `true` on successful clearing, `false` if failed partially or entirely.

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

Performs a decrement operation on a specified numeric cache item.
public decrement ( string $key, integer $offset = 1 ) : integer | boolean
$key string Key of numeric cache item to decrement.
$offset integer Offset to decrement - defaults to `1`.
Результат integer | boolean The item's new value on successful decrement, else `false`.

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

Will attempt to remove specified keys from the user space cache.
public delete ( array $keys ) : boolean
$keys array Keys to uniquely identify the cached items.
Результат boolean `true` on successful delete, `false` otherwise.

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

Performs an increment operation on a specified numeric cache item.
public increment ( string $key, integer $offset = 1 ) : integer | boolean
$key string Key of numeric cache item to increment
$offset integer Offset to increment - defaults to `1`.
Результат integer | boolean The item's new value on successful increment, else `false`.

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

Invalidates and cleans up expired items on-the-fly when found.
public read ( array $keys ) : array
$keys array Keys to uniquely identify the cached items.
Результат array Cached values keyed by cache keys on successful read, keys which could not be read will not be included in the results array.

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

Write values to the cache. All items to be cached will receive an expiration time of $expiry.
public write ( array $keys, string | integer $expiry = null ) : boolean
$keys array Key/value pairs with keys to uniquely identify the to-be-cached item.
$expiry string | integer A `strtotime()` compatible cache time or TTL in seconds. To persist an item use `\lithium\storage\Cache::PERSIST`.
Результат boolean `true` on successful write, `false` otherwise.