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.
Показать файл
Открыть проект
Примеры использования класса
Открытые методы
Метод |
Описание |
|
__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. |
|
Защищенные методы
Описание методов
__construct()
публичный Метод
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.
_parse()
защищенный Метод
Parses value from format.
Reads from file, parses its format and returns its expiry and value.
_write()
защищенный Метод
Compiles value to format and writes file.
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. |
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. |
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.
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.
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 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. |