class Cache (View source)

Cache::get('the-cache-key', function() { # this gets executed when cache is stale return "your cacheable datas"; });

Properties

static $adapter
static $options

Methods

static 
initialize(string $url, array $options = array())

Initializes the cache.

static 
flush()

No description

static mixed
get($key, $closure, $expire = null)

Attempt to retrieve a value from cache using a key. If the value is not found, then the closure method will be invoked, and the result will be stored in cache using that key.

static 
set($key, $var, $expire = null)

No description

static 
delete($key)

No description

Details

static initialize(string $url, array $options = array())

Initializes the cache.

With the $options array it's possible to define: - expiration of the key, (time in seconds) - a namespace for the key

this last one is useful in the case two applications use a shared key/store (for instance a shared Memcached db)

Ex: $cfg_ar = ActiveRecord\Config::instance(); $cfg_ar->set_cache('memcache://localhost:11211',array('namespace' => 'my_cool_app', 'expire' => 120 ));

In the example above all the keys expire after 120 seconds, and the all get a postfix 'my_cool_app'.

(Note: expiring needs to be implemented in your cache store.)

Parameters

string $url URL to your cache server
array $options Specify additional options

static flush()

static mixed get($key, $closure, $expire = null)

Attempt to retrieve a value from cache using a key. If the value is not found, then the closure method will be invoked, and the result will be stored in cache using that key.

Parameters

$key
$closure
$expire in seconds

Return Value

mixed

static set($key, $var, $expire = null)

Parameters

$key
$var
$expire

static delete($key)

Parameters

$key