Properties

$context

$context : object

Context object.

Type

object

$persist

$persist : boolean

Should the cache persist or not.

Type

boolean

$dir

$dir : string

Cache directory object.

Type

string

$cache

$cache : array

Holds the cached objects.

Type

array

$memory_limit

$memory_limit : integer

Holds the memory limit object.

Type

integer

$memory_low

$memory_low : integer

Holds the memory limit object

Type

integer

Methods

read()

read(integer|string  $key, string  $namespace = 'default') 

Fetches cached data.

Parameters

integer|string $key

Unique key of the cache file.

string $namespace

Optional. Where the cache contents are namespaced. Default: 'default'.

create()

create(integer|string  $key, mixed  $data, string  $namespace = 'default', integer  $ttl) 

Creates the cache file.

Parameters

integer|string $key

Unique key of the cache file.

mixed $data

Data that should be cached.

string $namespace

Optional. Where to namespace the cache contents. Default: 'default'.

integer $ttl

Time to live sets the life of the cache file. Default: 0 = expires immediately after request.

delete()

delete(integer|string  $key, string  $namespace = 'default') : boolean

Deletes a cache file based on unique key.

Parameters

integer|string $key

Unique key of cache file.

string $namespace

Optional. Where to namespace the cache contents. Default: 'default'.

Returns

boolean —

Returns true if the cache was deleted or false otherwise.

flush()

flush() : boolean

Flushes the file system cache completely.

Returns

boolean —

Returns true if the cache was purged or false otherwise.

flushNamespace()

flushNamespace(integer|string  $namespace = 'default') : boolean

Removes all cache items from a particular namespace.

Parameters

integer|string $namespace

Optional. Where the cache contents are namespaced. Default: 'default'.

Returns

boolean —

Returns true if the namespace was purged or false otherwise.

set()

set(integer|string  $key, mixed  $data, string  $namespace = 'default', integer  $ttl) : boolean

Sets the data contents into the cache.

Parameters

integer|string $key

Unique key of the cache file.

mixed $data

Data that should be cached.

string $namespace

Optional. Where the cache contents are namespaced. Default: 'default'.

integer $ttl

Time to live sets the life of the cache file. Default: 0 = expires immediately after request.

Returns

boolean —

Returns true if the cache was set and false otherwise.

getStats()

getStats() 

Echoes the stats of the cache.

Gives the cache hits, cache misses and cache uptime.

increment()

increment(integer|string  $key, integer  $offset = 1, string  $namespace = 'default') : false|integer

Increments numeric cache item's value.

Parameters

integer|string $key

The cache key to increment

integer $offset

Optional. The amount by which to increment the item's value. Default: 1.

string $namespace

Optional. The namespace the key is in. Default: 'default'.

Returns

false|integer —

False on failure, the item's new value on success.

decrement()

decrement(integer|string  $key, integer  $offset = 1, string  $namespace = 'default') : false|integer

Decrements numeric cache item's value.

Parameters

integer|string $key

The cache key to decrement.

integer $offset

Optional. The amount by which to decrement the item's value. Default: 1.

string $namespace

Optional. The namespace the key is in. Default: 'default'.

Returns

false|integer —

False on failure, the item's new value on success.

update()

update(integer|string  $key, mixed  $data, string  $namespace = 'default', integer  $ttl) : boolean

Updates a cache file based on unique ID.

This method only exists for CRUD completeness purposes and just basically calls the create method.

Parameters

integer|string $key

Unique key of the cache file.

mixed $data

Data that should be cached.

string $namespace

Optional. Where to namespace the cache contents. Default: 'default'.

integer $ttl

Time to live sets the life of the cache file. Default: no expiration.

Returns

boolean —

False if original value does not exist, true if contents were replaced

uniqueKey()

uniqueKey(integer|string  $key, string  $namespace = 'default') 

Generates a unique cache key.

Parameters

integer|string $key

Unique key for cache file.

string $namespace

Optional. Where the cache contents are namespaced. Default: 'default'.

exists()

exists(integer|string  $key, string  $namespace) : boolean

Serves as a utility method to determine whether a key exists in the cache.

Parameters

integer|string $key

Cache key to check for existence.

string $namespace

Cache namespace for the key existence check.

Returns

boolean —

Whether the cache item exists in the cache for the given key and namespace.

removeDir()

removeDir(string  $dir) 

Deletes cache/namespace directory.

Parameters

string $dir

Directory that should be removed.

cacheHits()

cacheHits() 

Counts the number of cache hits and writes it to a file.

cacheMisses()

cacheMisses() 

Counts the number of cache misses and writes it to a file.

removeStaleCache()

removeStaleCache(integer|string  $key, integer|string  $namespace = 'default', integer  $ttl) 

Removes any and all stale items from the cache.

Parameters

integer|string $key

Unqiue key of cache.

integer|string $namespace

Optional. Where the cache contents are namespaced. Default: 'default'.

integer $ttl

Time to live sets the life of the cache file. Default: 0.

keyToPath()

keyToPath(integer|string  $key, integer|string  $namespace) 

Retrieve the cache file.

Parameters

integer|string $key

Unqiue key of cache.

integer|string $namespace

Optional. Where the cache contents are namespaced. Default: 'default'.