This class provides several functions to cache data.
Currently there is only a garbage handling for the file driver implementation. The given storage backend like APC, APCu, Memcache or redis.io will handle this feature on their own.
You can use this class on two ways: Static usage or through cache objects that will be returned by Cache::forge();
Cache::set('username', 'mustermann', 300);
$cache = Cache::forge();
$cache->set('username', 'mustermann', 300);
Here is a list of available public methods for this class:
Create a new cache instance
Static | Yes | |||
Parameters | Parameter | Type | Default | Description |
$cache = Cache::forge();
Check given identifier exists in cache.
Static | Yes | |||
Parameters | Parameter | Type | Default | Description |
$identifier | String | Name of given cache object. |
Cache::check('countries');
Create a new cache object. If $ttl is set to false, the default expiration from config file for given cache storage will be used.
Static | Yes | |||
Parameters | Parameter | Type | Default | Description |
$identifier | String | Name for cache object. | ||
$payload | mixed | Content for cache object | ||
$ttl | mixed | Time to live; store the payload for ttl seconds in cache. If set to false, the default expiration from config file for given cache storage will be used. If ttl is 0, the cache object will persist until it is removed from cache manually. |
Cache::set('username', 'Mustermann', 3600);
Get cache object by given identifier.
Static | Yes | |||
Parameters | Parameter | Type | Default | Description |
$identifier | String | Name of cache object. |
Cache::get('username');
Increase a value in cache object.
Static | Yes | |||
Parameters | Parameter | Type | Default | Description |
$identifier | String | Name of cache object. | ||
$step | String | Value that should be add to given cache object. |
Cache::increase('article.mainboards', 5);
Decrease a value in cache object.
Static | Yes | |||
Parameters | Parameter | Type | Default | Description |
$identifier | String | Name of cache object. | ||
$step | String | Value that should be decrease to given cache object. |
Cache::decrease('articles.mainboards', 2);
Delete given cache object.
Static | Yes | |||
Parameters | Parameter | Type | Default | Description |
$identifier | String | Name of cache object. |
Cache::delete('articles.mainboards');
Check if cache files (for file driven caching) are already expired and delete them.
The file cache driver perform every configured minute a garbadge collection. You can set the time in the config file.
Static | Yes |
Cache::garbadge_collector();