Methods |
public
|
__construct(string $filename = ':memory:')
Creates a new CacheStore object
Creates a new CacheStore object
Implements
|
#
|
public
|
set($key, $value, $ttl = null): bool
Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
Parameters
$key |
The key of the item to store.
|
$value |
The value of the item to store, must be serializable.
|
$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.
|
Returns
True on success and false on failure.
Implements
|
#
|
public
|
has($key): bool
Determines whether an item is present in the cache.
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
Implements
|
#
|
public
|
get($key, $default = null)
Fetches a value from the cache.
Fetches a value from the cache.
Parameters
$key |
The unique key of this item in the cache.
|
$default |
Default value to return if the key does not exist.
|
Returns
The value of the item from the cache, or $default in case of cache miss.
Implements
|
#
|
public
|
getInstanceOf($key, string $class, ?object $default = null): ?object
Retrieve an instance of a class stored under a given key
Retrieve an instance of a class stored under a given key
Returns
$default if the item has expired, doesn't exist or is
not an instance of $class .
Implements
|
#
|
public
|
getArray($key, ?array $default = null): ?array
Retrieve an array stored under a given key
Retrieve an array stored under a given key
Returns
$default if the item has expired, doesn't exist or
is not an array.
Implements
|
#
|
public
|
getInt($key, ?int $default = null): ?int
Retrieve an integer stored under a given key
Retrieve an integer stored under a given key
Returns
$default if the item has expired, doesn't exist or is
not an integer.
Implements
|
#
|
public
|
getString($key, ?string $default = null): ?string
Retrieve a string stored under a given key
Retrieve a string stored under a given key
Returns
$default if the item has expired, doesn't exist or
is not a string.
Implements
|
#
|
public
|
delete($key): bool
Delete an item from the cache by its unique key.
Delete an item from the cache by its unique key.
Parameters
$key |
The unique cache key of the item to delete.
|
Returns
True if the item was successfully removed. False if there was an error.
Implements
|
#
|
public
|
clear(): bool
Wipes clean the entire cache's keys.
Wipes clean the entire cache's keys.
Returns
True on success and false on failure.
Implements
|
#
|
public
|
clearExpired(): true
Delete expired items
|
#
|
public
|
getMultiple($keys, $default = null)
Obtains multiple cache items by their unique keys.
Obtains multiple cache items by their unique keys.
Parameters
$keys |
A list of keys that can obtained in a single operation.
|
$default |
Default value to return for keys that do not exist.
|
Returns
A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value.
Implements
|
#
|
public
|
setMultiple($values, $ttl = null): bool
Persists a set of key => value pairs in the cache, with an optional TTL.
Persists a set of key => value pairs in the cache, with an optional TTL.
Parameters
$values |
A list of key => value pairs for a multiple-set operation.
|
$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.
|
Returns
True on success and false on failure.
Implements
|
#
|
public
|
deleteMultiple($keys): bool
Deletes multiple cache items in a single operation.
Deletes multiple cache items in a single operation.
Parameters
$keys |
A list of string-based keys to be deleted.
|
Returns
True if the items were successfully removed. False if there was an error.
Implements
|
#
|
public
|
getItemCount(): int
Get the number of unexpired items in the store
Get the number of unexpired items in the store
Implements
|
#
|
public
|
getItemKeys(): array
Get a list of keys under which unexpired items are stored
Get a list of keys under which unexpired items are stored
Implements
|
#
|
public
|
asOfNow(?int $now = null): CacheInterface
Get a copy of the store where items do not expire over time
Get a copy of the store where items do not expire over time
Returns an instance where items expire relative to the time of the call
to {@see asOfNow()}, allowing clients to mitigate race conditions like
items expiring or being replaced between subsequent calls.
Only one copy of the store can be open at a time. Copies are closed via
{@see close()} or by going out of scope.
Parameters
$now |
If given, items expire relative to this Unix
timestamp instead of the time {@see asOfNow()} is called.
|
Implements
|
#
|
public
|
close(): void
Close the database and unload any facades where the store is the
underlying instance
Close the database and unload any facades where the store is the
underlying instance
Overrides
Implements
|
#
|