LightPHPFramework

Cache Class

This class provides several functions to cache data.

Garbage Collection

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.

Usage

You can use this class on two ways: Static usage or through cache objects that will be returned by Cache::forge();

Example for static usage
		
Cache::set('username', 'mustermann', 300);
		
	
Example in object context
		
$cache = Cache::forge();
$cache->set('username', 'mustermann', 300);
		
	

List of public methods

Here is a list of available public methods for this class:


forge()

Create a new cache instance

Static Yes
Parameters Parameter Type Default Description
Example
		
$cache = Cache::forge();
		
	

check($identifier)

Check given identifier exists in cache.

Static Yes
Parameters Parameter Type Default Description
$identifier String Name of given cache object.
Example
		
Cache::check('countries');
		
	

set($identifier, $payload, $ttl)

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.
Example
		
Cache::set('username', 'Mustermann', 3600);
		
	

get($identifier)

Get cache object by given identifier.

Static Yes
Parameters Parameter Type Default Description
$identifier String Name of cache object.
Example
		
Cache::get('username');
		
	

increase($identifier, $step)

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.
Example
		
Cache::increase('article.mainboards', 5);
		
	

decrease($identifier, $step)

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.
Example
		
Cache::decrease('articles.mainboards', 2);
		
	

delete($identifier)

Delete given cache object.

Static Yes
Parameters Parameter Type Default Description
$identifier String Name of cache object.
Example
		
Cache::delete('articles.mainboards');
		
	

garbadge_collector()

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
Example
		
Cache::garbadge_collector();