Class: Cache

This is a basic class that immitates Memcache via the filesystem so handlers can use "poor man's caching" even if Memcache ins't available.

Also provides an init() method that initializes the correct cache for the current request (Memcache, Redis, or itself).


public $dir = 'cache/datastore'

Directory to use for cache.


public __construct ($dir = 'cache/datastore')

Constructor method creates the directory if it's missing.

public static init ($conf)

Initialize the correct cache based on the global configuration and return the cache object (lib/MemcacheExt, lib/MemcacheAPC, lib/MemcacheXCache, lib/MemcacheRedis, or lib/Cache).

private _set_timeout ($key, $timeout)

Create a timeout file to store the timeout of the cached data. Uses a similarly named dot-file to the main file that contains only the timeout value.

private _has_timed_out ($key)

Checks whether a key's timeout has expired. If it has, it also deletes the timeout dot-file.

public cache ($key, $timeout, $function)

Emulates MemcacheExt::cache.

public get ($key)

Emulates Memcache::get.

public add ($key, $val, $flags = 0, $timeout = false)

Emulates Memcache::add.

public replace ($key, $val, $flags = 0, $timeout = false)

Emulates Memcache::replace.

public set ($key, $val, $flags = 0, $timeout = false)

Emulates Memcache::set.

public increment ($key, $value = 1)

Emulates Memcache::increment.

public decrement ($key, $value = 1)

Emulates Memcache::decrement.

public flush ()

Emulates Memcache::flush.

public delete ($key)

Emulates Memcache::delete.