This class is for using Memcache. It provides 7 public methods.

Get

$var = Cache::get($key)

Returns previously stored data if an item with such key exists on the server at this moment. Returns the string associated with the key or an array of found key-value pairs when key is an array. Returns FALSE on failure, key is not found or key is an empty array.

Set

$success = Cache::set($key,$var,$expire=0)

Stores an item var with key on the memcached server. Parameter expire is expiration time in seconds. If it’s 0, the item never expires (but memcached server doesn’t guarantee this item to be stored all the time, it could be deleted from the cache to make place for other items). Returns TRUE on success or FALSE on failure.

Delete

$success = Cache::delete($key)

Deletes an item with the key. Returns TRUE on success or FALSE on failure.

Add

$success = Cache::add($key,$var,$expire=0)

Stores variable var with key only if such key doesn’t exist at the server yet. Returns TRUE on success or FALSE on failure. Returns FALSE if such key already exist. For the rest add() behaves similarly to set().

Replace

$success = Cache::replace($key,$var,$expire=0)

Should be used to replace value of existing item with key. Returns FALSE in the case that an item with such key doesn’t exists. For the rest replace() behaves similarly to set(). Returns TRUE on success or FALSE on failure.

Increment

$var = Cache::increment($key,$value=1)

Increments value of an item by the specified value. If item specified by key was not numeric and cannot be converted to a number, it will change its value to the specified value. Method does not create an item if it doesn’t already exist. Returns new items value on success or FALSE on failure.

Decrement

$var = Cache::decrement($key,$value=1)

Decrements value of the item by value. Similarly to increment(), current value of the item is being converted to numerical and after that value is subtracted. Method does not create an item if it didn’t exist. Returns item’s new value on success or FALSE on failure.