Class SimpleCacheEngine

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

Cake\Cache\SimpleCacheEngine implements Psr\SimpleCache\CacheInterface, Cake\Cache\CacheEngineInterface

Properties summary

Method Summary

  • __construct() public
    Constructor
  • add() public
    Write data for key into a cache engine if it doesn't exist already.
  • clear() public
    Wipes clean the entire cache's keys.
  • clearGroup() public
    Clear all values belonging to the named group.
  • decrement() public
    Decrement a number under the key and return decremented value
  • delete() public
    Delete an item from the cache by its unique key.
  • Deletes multiple cache items in a single operation.
  • ensureValidKey() protected
    Ensure the validity of the given cache key.
  • ensureValidKeys() protected
    Ensure the validity of the given cache keys.
  • get() public
    Fetches the value for a given key from the cache.
  • getMultiple() public
    Obtains multiple cache items by their unique keys.
  • has() public
    Determines whether an item is present in the cache.
  • increment() public
    Increment a number under the key and return incremented value
  • set() public
    Persists data in the cache, uniquely referenced by the given key with an optional expiration TTL time.
  • setMultiple() public
    Persists a set of key => value pairs in the cache, with an optional TTL.

Method Detail

__construct()source public

__construct( Cake\Cache\CacheEngine $innerEngine )

Constructor

Parameters

Cake\Cache\CacheEngine $innerEngine
The decorated engine.

add()source public

add( string $key , mixed $value )

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.


Implementation of

Cake\Cache\CacheEngineInterface::add()

clear()source public

clear( )

Wipes clean the entire cache's keys.

Returns

boolean
True on success and false on failure.

clearGroup()source public

clearGroup( string $group )

Clear all values belonging to the named group.

Parameters

string $group
name of the group to be cleared

Returns

boolean

Implementation of

Cake\Cache\CacheEngineInterface::clearGroup()

decrement()source public

decrement( string $key , integer $offset = 1 )

Decrement a number under the key and return decremented value

Parameters

string $key
Identifier for the data
integer $offset optional 1
How much to subtract

Returns

boolean|integer
New incremented value, false otherwise

Implementation of

Cake\Cache\CacheEngineInterface::decrement()

delete()source public

delete( string $key )

Delete an item from the cache by its unique key.

Parameters

string $key
The unique cache key of the item to delete.

Returns

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

Throws

Cake\Cache\InvalidArgumentException
If the $key string is not a legal value.

deleteMultiple()source public

deleteMultiple( iterable $keys )

Deletes multiple cache items in a single operation.

Parameters

iterable $keys
A list of string-based keys to be deleted.

Returns

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

Throws

Cake\Cache\InvalidArgumentException

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


ensureValidKey()source protected

ensureValidKey( string $key )

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()source protected

ensureValidKeys( mixed $keys )

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.

get()source public

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

Fetches the value for a given key from the cache.

Parameters

string $key
The unique key of this item in the cache.
mixed $default optional null
Default value to return if the key does not exist.

Returns

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

Throws

Cake\Cache\InvalidArgumentException
If the $key string is not a legal value.

getMultiple()source public

getMultiple( iterable $keys , mixed $default = null )

Obtains multiple cache items by their unique keys.

Parameters

iterable $keys
A list of keys that can obtained in a single operation.
mixed $default optional null
Default value to return for keys that do not exist.

Returns

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

Throws

Cake\Cache\InvalidArgumentException

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


has()source public

has( string $key )

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.

Returns

boolean

Throws

Cake\Cache\InvalidArgumentException
If the $key string is not a legal value.

increment()source public

increment( string $key , integer $offset = 1 )

Increment a number under the key and return incremented value

Parameters

string $key
Identifier for the data
integer $offset optional 1
How much to add

Returns

boolean|integer
New incremented value, false otherwise

Implementation of

Cake\Cache\CacheEngineInterface::increment()

set()source public

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

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 null

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.

Returns

boolean
True on success and false on failure.

Throws

Cake\Cache\InvalidArgumentException
MUST be thrown if the $key string is not a legal value.

setMultiple()source public

setMultiple( iterable $values , null|integer|DateInterval $ttl = null )

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

Parameters

iterable $values
A list of key => value pairs for a multiple-set operation.
null|integer|DateInterval $ttl optional null

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.

Returns

boolean
True on success and false on failure.

Throws

Cake\Cache\InvalidArgumentException

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


Properties detail

$innerEnginesource

protected Cake\Cache\CacheEngine

The wrapped cache engine object.

© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.8/class-Cake.Cache.SimpleCacheEngine.html