CRM_Utils_Cache_Memcached
in package
implements
CRM_Utils_Cache_Interface
uses
CRM_Utils_Cache_NaiveMultipleTrait
Tags
Table of Contents
Interfaces
Constants
- DEFAULT_HOST = 'localhost'
- DEFAULT_PORT = 11211
- DEFAULT_PREFIX = ''
- DEFAULT_TIMEOUT = 3600
- MAX_KEY_LEN = 200
- NS_LOCAL_TTL = 5
- If another process clears namespace, we'll find out in ~5 sec.
Properties
- $_cache : Memcached
- The actual memcache object.
- $_host : string
- The host name of the memcached server
- $_port : int
- The port on which to connect on
- $_prefix : string
- The prefix prepended to cache keys.
- $_timeout : int
- The default timeout to use
- $_truePrefix : null|array<string|int, mixed>
Methods
- __construct() : CRM_Utils_Cache_Memcached
- Constructor.
- cleanKey() : mixed|string
- clear() : bool
- Delete all values from the cache.
- delete() : mixed
- Delete a value from the cache.
- deleteMultiple() : bool
- Deletes multiple cache items in a single operation.
- flush() : bool
- Delete all values from the cache.
- get() : mixed
- Get a value from the cache.
- getMultiple() : iterable<string|int, mixed>
- Obtains multiple cache items by their unique keys.
- has() : bool
- Determines whether an item is present in the cache.
- set() : bool
- Set the value in the cache.
- setMultiple() : bool
- Persists a set of key => value pairs in the cache, with an optional TTL.
- getTruePrefix() : mixed
- assertIterable() : mixed
Constants
DEFAULT_HOST
public
mixed
DEFAULT_HOST
= 'localhost'
DEFAULT_PORT
public
mixed
DEFAULT_PORT
= 11211
DEFAULT_PREFIX
public
mixed
DEFAULT_PREFIX
= ''
DEFAULT_TIMEOUT
public
mixed
DEFAULT_TIMEOUT
= 3600
MAX_KEY_LEN
public
mixed
MAX_KEY_LEN
= 200
NS_LOCAL_TTL
If another process clears namespace, we'll find out in ~5 sec.
public
mixed
NS_LOCAL_TTL
= 5
Properties
$_cache
The actual memcache object.
protected
Memcached
$_cache
$_host
The host name of the memcached server
protected
string
$_host
= self::DEFAULT_HOST
$_port
The port on which to connect on
protected
int
$_port
= self::DEFAULT_PORT
$_prefix
The prefix prepended to cache keys.
protected
string
$_prefix
= self::DEFAULT_PREFIX
If we are using the same memcache instance for multiple CiviCRM installs, we must have a unique prefix for each install to prevent the keys from clobbering each other.
$_timeout
The default timeout to use
protected
int
$_timeout
= self::DEFAULT_TIMEOUT
$_truePrefix
protected
null|array<string|int, mixed>
$_truePrefix
= \NULL
This is the effective prefix. It may be bumped up whenever the dataset is flushed.
Tags
Methods
__construct()
Constructor.
public
__construct(array<string|int, mixed> $config) : CRM_Utils_Cache_Memcached
Parameters
- $config : array<string|int, mixed>
-
An array of configuration params.
Return values
CRM_Utils_Cache_MemcachedcleanKey()
public
cleanKey(mixed $key) : mixed|string
Parameters
- $key : mixed
Return values
mixed|stringclear()
Delete all values from the cache.
public
clear() : bool
NOTE: flush() and clear() should be aliases. flush() is specified by Civi's traditional interface, and clear() is specified by PSR-16.
Return values
booldelete()
Delete a value from the cache.
public
delete(mixed $key) : mixed
Parameters
- $key : mixed
deleteMultiple()
Deletes multiple cache items in a single operation.
public
deleteMultiple(iterable<string|int, mixed> $keys) : bool
Parameters
- $keys : iterable<string|int, mixed>
-
A list of string-based keys to be deleted.
Tags
Return values
bool —True if the items were successfully removed. False if there was an error.
flush()
Delete all values from the cache.
public
flush() : bool
Return values
boolget()
Get a value from the cache.
public
get(mixed $key[, mixed $default = NULL ]) : mixed
Parameters
- $key : mixed
- $default : mixed = NULL
getMultiple()
Obtains multiple cache items by their unique keys.
public
getMultiple(iterable<string|int, mixed> $keys[, mixed $default = NULL ]) : iterable<string|int, mixed>
Parameters
- $keys : iterable<string|int, mixed>
-
A list of keys that can obtained in a single operation.
- $default : mixed = NULL
-
Default value to return for keys that do not exist.
Tags
Return values
iterable<string|int, mixed> —A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value.
has()
Determines whether an item is present in the cache.
public
has(string $key) : bool
Parameters
- $key : string
Tags
Return values
boolset()
Set the value in the cache.
public
set(mixed $key, mixed $value[, null|int|DateInterval $ttl = NULL ]) : bool
Parameters
- $key : mixed
- $value : mixed
- $ttl : null|int|DateInterval = NULL
Tags
Return values
boolsetMultiple()
Persists a set of key => value pairs in the cache, with an optional TTL.
public
setMultiple(iterable<string|int, mixed> $values[, null|int|DateInterval $ttl = NULL ]) : bool
Parameters
- $values : iterable<string|int, mixed>
-
A list of key => value pairs for a multiple-set operation.
- $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.
Tags
Return values
bool —True on success and false on failure.
getTruePrefix()
protected
getTruePrefix() : mixed
assertIterable()
private
assertIterable(mixed $func, mixed $keys) : mixed
Parameters
- $func : mixed
- $keys : mixed