PHP Class 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.
See also: lithium\storage\cache\adapter
Inheritance: extends lithium\core\Object
Show file Open project: unionofrad/lithium Class Usage Examples

Public Methods

Method Description
__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.

Protected Methods

Method Description
_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.

Method Details

__construct() public method

Constructor.
See also: 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'`.
return void

_compile() protected method

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.
return string The compiled data string.

_delete() protected method

Deletes a file using the corresponding cached item key.
See also: lithium\storage\cache\adapter\File::delete()
protected _delete ( string $key ) : boolean
$key string Key to uniquely identify the cached item.
return boolean `true` on success, `false` otherwise.

_parse() protected method

Parses value from format.
protected _parse ( string $data ) : array
$data string Compiled data string.
return array Array with `expiry` and `value`.

_read() protected method

Reads from file, parses its format and returns its expiry and value.
See also: lithium\storage\cache\adapter\File::read()
protected _read ( string $key ) : array | boolean
$key string Key to uniquely identify the cached item.
return array | boolean Array with `expiry` and `value` or `false` otherwise.

_write() protected method

Compiles value to format and writes file.
See also: 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.
return boolean `true` on success, `false` otherwise.

clean() public method

The operation will continue to remove keys even if removing one single key fails, cleaning thoroughly as possible.
public clean ( ) : boolean
return boolean `true` on successful cleaning, `false` if failed partially or entirely.

clear() public method

The operation will continue to remove keys even if removing one single key fails, clearing thoroughly as possible.
public clear ( ) : boolean
return boolean `true` on successful clearing, `false` if failed partially or entirely.

decrement() public method

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`.
return integer | boolean The item's new value on successful decrement, else `false`.

delete() public method

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.
return boolean `true` on successful delete, `false` otherwise.

increment() public method

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`.
return integer | boolean The item's new value on successful increment, else `false`.

read() public method

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.
return 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() public method

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`.
return boolean `true` on successful write, `false` otherwise.