BaseHandler
in package
implements
CacheInterface
Base class for cache handling
Tags
Table of Contents
Interfaces
Constants
- MAX_KEY_LENGTH = PHP_INT_MAX
- Maximum key length.
- RESERVED_CHARACTERS = '{}()/\@:'
- Reserved characters that cannot be used in a key or tag. May be overridden by the config.
Properties
- $prefix : string
- Prefix to apply to cache keys.
Methods
- ping() : bool
- Check if connection is alive.
- reconnect() : bool
- Reconnect to the cache server.
- remember() : mixed
- Attempts to get an item from the cache, or executes the callback and stores the result on cache miss.
- validateKey() : string
- Validates a cache key according to PSR-6.
Constants
MAX_KEY_LENGTH
Maximum key length.
public
mixed
MAX_KEY_LENGTH
= PHP_INT_MAX
RESERVED_CHARACTERS
Reserved characters that cannot be used in a key or tag. May be overridden by the config.
in favor of the Cache config
public
mixed
RESERVED_CHARACTERS
= '{}()/\@:'
From https://github.com/symfony/cache-contracts/blob/c0446463729b89dd4fa62e9aeecc80287323615d/ItemInterface.php#L43
Properties
$prefix
Prefix to apply to cache keys.
protected
string
$prefix
May not be used by all handlers.
Methods
ping()
Check if connection is alive.
public
ping() : bool
Default implementation for handlers that don't require connection management. Handlers with persistent connections (Redis, Predis, Memcached) should override this.
Return values
boolreconnect()
Reconnect to the cache server.
public
reconnect() : bool
Default implementation for handlers that don't require connection management. Handlers with persistent connections (Redis, Predis, Memcached) should override this.
Return values
boolremember()
Attempts to get an item from the cache, or executes the callback and stores the result on cache miss.
public
remember(string $key, int $ttl, Closure $callback) : mixed
Parameters
- $key : string
-
Cache item name
- $ttl : int
-
Time To Live, in seconds
- $callback : Closure
-
Callback executed on cache miss
validateKey()
Validates a cache key according to PSR-6.
public
static validateKey(mixed $key[, string $prefix = '' ]) : string
Keys that exceed MAX_KEY_LENGTH are hashed. From https://github.com/symfony/cache/blob/7b024c6726af21fd4984ac8d1eae2b9f3d90de88/CacheItem.php#L158
Parameters
- $key : mixed
-
The key to validate
- $prefix : string = ''
-
Optional prefix to include in length calculations