CacheInterface
in
Table of Contents
Constants
- TTL_DAY = 86400
- TTL_HOUR = 3600
- TTL_MINUTE = 60
Methods
- clear() : void
- Wipe clean the entire cache's keys
- delete() : void
- Delete an item from the cache by its unique key
- deleteMultiple() : void
- Delete multiple cache items in a single operation
- exists() : bool
- Identify if an item is in the cache.
- get() : mixed
- Fetch a value from the cache.
- getMultiple() : array<string|int, mixed>
- Obtain multiple cache items by their unique keys
- set() : bool
- Persist data in the cache, uniquely referenced by a key with an optional expiration TTL time.
- setMultiple() : bool
- Persisting a set of key => value pairs in the cache, with an optional TTL.
Constants
TTL_DAY
public
mixed
TTL_DAY
= 86400
TTL_HOUR
public
mixed
TTL_HOUR
= 3600
TTL_MINUTE
public
mixed
TTL_MINUTE
= 60
Methods
clear()
Wipe clean the entire cache's keys
public
clear() : void
delete()
Delete an item from the cache by its unique key
public
delete(string $key) : void
Parameters
- $key : string
-
The unique cache key of the item to delete
deleteMultiple()
Delete multiple cache items in a single operation
public
deleteMultiple(array<string|int, mixed>|Traversable $keys) : void
Parameters
- $keys : array<string|int, mixed>|Traversable
-
The array of string-based keys to be deleted
exists()
Identify if an item is in the cache.
public
exists(string $key) : bool
NOTE: It is recommended that exists() 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 exists() will return true and immediately after, another script can remove it making the state of your app out of date.
Parameters
- $key : string
-
The cache item key
Return values
boolget()
Fetch a value from the cache.
public
get(string $key) : mixed
Parameters
- $key : string
-
The unique key of this item in the cache
Return values
mixed —The value of the item from the cache, or null in case of cache miss
getMultiple()
Obtain multiple cache items by their unique keys
public
getMultiple(array<string|int, mixed>|Traversable $keys) : array<string|int, mixed>
Parameters
- $keys : array<string|int, mixed>|Traversable
-
A list of keys that can obtained in a single operation.
Return values
array<string|int, mixed> —An array of key => value pairs. Cache keys that do not exist or are stale will have a value of null.
set()
Persist data in the cache, uniquely referenced by a key with an optional expiration TTL time.
public
set(string $key, mixed $value[, null|int|DateInterval $ttl = null ]) : bool
Parameters
- $key : string
-
The key of the item to store
- $value : mixed
-
The value of the item to store
- $ttl : null|int|DateInterval = 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.
Return values
bool —True on success and false on failure
setMultiple()
Persisting a set of key => value pairs in the cache, with an optional TTL.
public
setMultiple(array<string|int, mixed>|Traversable $items[, null|int|DateInterval $ttl = null ]) : bool
Parameters
- $items : array<string|int, mixed>|Traversable
-
An array of key => value pairs for a multiple-set operation.
- $ttl : null|int|DateInterval = null
-
Optional. The amount of seconds from the current time that the item will exist in the cache for. If this is null then the cache backend will fall back to its own default behaviour.
Return values
bool —True on success and false on failure