\Cake\CacheSimpleCacheEngine

Wrapper for Cake engines that allow them to support the PSR16 Simple Cache Interface

Summary

Methods
Properties
Constants
__construct()
get()
set()
delete()
clear()
getMultiple()
setMultiple()
deleteMultiple()
has()
add()
increment()
decrement()
clearGroup()
No public properties found
No constants found
ensureValidKey()
ensureValidKeys()
$innerEngine
N/A
No private methods found
No private properties found
N/A

Properties

$innerEngine

$innerEngine : \Cake\Cache\CacheEngine

The wrapped cache engine object.

Type

\Cake\Cache\CacheEngine

Methods

__construct()

__construct(\Cake\Cache\CacheEngine  $innerEngine) 

Constructor

Parameters

\Cake\Cache\CacheEngine $innerEngine

The decorated engine.

get()

get(string  $key, mixed  $default = null) : mixed

Fetches the value for a given key from the cache.

Parameters

string $key

The unique key of this item in the cache.

mixed $default

Default value to return if the key does not exist.

Throws

\Cake\Cache\InvalidArgumentException

If the $key string is not a legal value.

Returns

mixed —

The value of the item from the cache, or $default in case of cache miss.

set()

set(string  $key, mixed  $value, null|integer|\DateInterval  $ttl = null) : boolean

Persists data in the cache, uniquely referenced by the given key with an optional expiration TTL time.

Parameters

string $key

The key of the item to store.

mixed $value

The value of the item to store, must be serializable.

null|integer|\DateInterval $ttl

Optional. The TTL value of this item. If no value is sent and the driver supports TTL then the library may set a default value for it or let the driver take care of that.

Throws

\Cake\Cache\InvalidArgumentException

MUST be thrown if the $key string is not a legal value.

Returns

boolean —

True on success and false on failure.

delete()

delete(string  $key) : boolean

Delete an item from the cache by its unique key.

Parameters

string $key

The unique cache key of the item to delete.

Throws

\Cake\Cache\InvalidArgumentException

If the $key string is not a legal value.

Returns

boolean —

True if the item was successfully removed. False if there was an error.

clear()

clear() : boolean

Wipes clean the entire cache's keys.

Returns

boolean —

True on success and false on failure.

getMultiple()

getMultiple(\Cake\Cache\iterable  $keys, mixed  $default = null) : \Cake\Cache\iterable

Obtains multiple cache items by their unique keys.

Parameters

\Cake\Cache\iterable $keys

A list of keys that can obtained in a single operation.

mixed $default

Default value to return for keys that do not exist.

Throws

\Cake\Cache\InvalidArgumentException

If $keys is neither an array nor a Traversable, or if any of the $keys are not a legal value.

Returns

\Cake\Cache\iterable —

A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value.

setMultiple()

setMultiple(\Cake\Cache\iterable  $values, null|integer|\DateInterval  $ttl = null) : boolean

Persists a set of key => value pairs in the cache, with an optional TTL.

Parameters

\Cake\Cache\iterable $values

A list of key => value pairs for a multiple-set operation.

null|integer|\DateInterval $ttl

Optional. The TTL value of this item. If no value is sent and the driver supports TTL then the library may set a default value for it or let the driver take care of that.

Throws

\Cake\Cache\InvalidArgumentException

If $values is neither an array nor a Traversable, or if any of the $values are not a legal value.

Returns

boolean —

True on success and false on failure.

deleteMultiple()

deleteMultiple(\Cake\Cache\iterable  $keys) : boolean

Deletes multiple cache items in a single operation.

Parameters

\Cake\Cache\iterable $keys

A list of string-based keys to be deleted.

Throws

\Cake\Cache\InvalidArgumentException

If $keys is neither an array nor a Traversable, or if any of the $keys are not a legal value.

Returns

boolean —

True if the items were successfully removed. False if there was an error.

has()

has(string  $key) : boolean

Determines whether an item is present in the cache.

NOTE: It is recommended that has() is only to be used for cache warming type purposes and not to be used within your live applications operations for get/set, as this method is subject to a race condition where your has() will return true and immediately after, another script can remove it making the state of your app out of date.

Parameters

string $key

The cache item key.

Throws

\Cake\Cache\InvalidArgumentException

If the $key string is not a legal value.

Returns

boolean

add()

add(string  $key, mixed  $value) : boolean

Write data for key into a cache engine if it doesn't exist already.

Parameters

string $key

Identifier for the data.

mixed $value

Data to be cached - anything except a resource.

Returns

boolean —

True if the data was successfully cached, false on failure. Or if the key existed already.

increment()

increment(string  $key, integer  $offset = 1) : boolean|integer

Increment a number under the key and return incremented value

Parameters

string $key

Identifier for the data

integer $offset

How much to add

Returns

boolean|integer —

New incremented value, false otherwise

decrement()

decrement(string  $key, integer  $offset = 1) : boolean|integer

Decrement a number under the key and return decremented value

Parameters

string $key

Identifier for the data

integer $offset

How much to subtract

Returns

boolean|integer —

New incremented value, false otherwise

clearGroup()

clearGroup(string  $group) : boolean

Clear all values belonging to the named group.

Each implementation needs to decide whether actually delete the keys or just augment a group generation value to achieve the same result.

Parameters

string $group

name of the group to be cleared

Returns

boolean

ensureValidKey()

ensureValidKey(string  $key) : void

Ensure the validity of the given cache key.

Parameters

string $key

Key to check.

Throws

\Cake\Cache\InvalidArgumentException

When the key is not valid.

ensureValidKeys()

ensureValidKeys(mixed  $keys) : void

Ensure the validity of the given cache keys.

Parameters

mixed $keys

The keys to check.

Throws

\Cake\Cache\InvalidArgumentException

When the keys are not valid.