MemcachedAdapter
extends AbstractAdapter
in package
Tags
Table of Contents
Constants
- MAX_KEY_LENGTH = 250
- RESERVED_MEMCACHED = " \n\r\t\v\f\x00"
- We are replacing characters that are illegal in Memcached keys with reserved characters from {@see \Symfony\Contracts\Cache\ItemInterface::RESERVED_CHARACTERS} that are legal in Memcached.
- RESERVED_PSR6 = '@()\{}/'
Properties
- $client : Memcached
- $lazyClient : Memcached
- $marshaller : MarshallerInterface
Methods
- __construct() : mixed
- Using a MemcachedAdapter with a TagAwareAdapter for storing tags is discouraged.
- commit() : bool
- Persists any deferred cache items.
- createConnection() : Memcached
- Creates a Memcached instance.
- createSystemCache() : AdapterInterface
- Returns the best possible adapter that your runtime supports.
- isSupported() : bool
- doClear() : bool
- doDelete() : bool
- doFetch() : iterable<string|int, mixed>
- doHave() : bool
- doSave() : array<string|int, mixed>|bool
- checkResultCode() : mixed
- decodeKey() : string
- encodeKey() : string
- getClient() : Memcached
Constants
MAX_KEY_LENGTH
private
mixed
MAX_KEY_LENGTH
= 250
RESERVED_MEMCACHED
We are replacing characters that are illegal in Memcached keys with reserved characters from {@see \Symfony\Contracts\Cache\ItemInterface::RESERVED_CHARACTERS} that are legal in Memcached.
private
mixed
RESERVED_MEMCACHED
= " \n\r\t\v\f\x00"
Note: don’t use AbstractAdapter::NS_SEPARATOR.
RESERVED_PSR6
private
mixed
RESERVED_PSR6
= '@()\{}/'
Properties
$client
private
Memcached
$client
$lazyClient
private
Memcached
$lazyClient
$marshaller
private
MarshallerInterface
$marshaller
Methods
__construct()
Using a MemcachedAdapter with a TagAwareAdapter for storing tags is discouraged.
public
__construct(Memcached $client[, string $namespace = '' ][, int $defaultLifetime = 0 ][, MarshallerInterface|null $marshaller = null ]) : mixed
Using a RedisAdapter is recommended instead. If you cannot do otherwise, be aware that:
- the Memcached::OPT_BINARY_PROTOCOL must be enabled (that's the default when using MemcachedAdapter::createConnection());
- tags eviction by Memcached's LRU algorithm will break by-tags invalidation; your Memcached memory should be large enough to never trigger LRU.
Using a MemcachedAdapter as a pure items store is fine.
Parameters
- $client : Memcached
- $namespace : string = ''
- $defaultLifetime : int = 0
- $marshaller : MarshallerInterface|null = null
commit()
Persists any deferred cache items.
public
commit() : bool
Return values
bool —True if all not-yet-saved items were successfully saved or there were none. False otherwise.
createConnection()
Creates a Memcached instance.
public
static createConnection(array<string|int, array<string|int, mixed>>|string|array<string|int, string> $servers[, array<string|int, mixed> $options = [] ]) : Memcached
By default, the binary protocol, no block, and libketama compatible options are enabled.
Examples for servers:
- 'memcached://user:pass@localhost?weight=33'
- [['localhost', 11211, 33]]
Parameters
- $servers : array<string|int, array<string|int, mixed>>|string|array<string|int, string>
-
An array of servers, a DSN, or an array of DSNs
- $options : array<string|int, mixed> = []
Tags
Return values
MemcachedcreateSystemCache()
Returns the best possible adapter that your runtime supports.
public
static createSystemCache(string $namespace, int $defaultLifetime, string $version, string $directory[, LoggerInterface|null $logger = null ]) : AdapterInterface
Using ApcuAdapter makes system caches compatible with read-only filesystems.
Parameters
- $namespace : string
- $defaultLifetime : int
- $version : string
- $directory : string
- $logger : LoggerInterface|null = null
Return values
AdapterInterfaceisSupported()
public
static isSupported() : bool
Return values
booldoClear()
protected
doClear(string $namespace) : bool
Parameters
- $namespace : string
Return values
booldoDelete()
protected
doDelete(array<string|int, mixed> $ids) : bool
Parameters
- $ids : array<string|int, mixed>
Return values
booldoFetch()
protected
doFetch(array<string|int, mixed> $ids) : iterable<string|int, mixed>
Parameters
- $ids : array<string|int, mixed>
Return values
iterable<string|int, mixed>doHave()
protected
doHave(string $id) : bool
Parameters
- $id : string
Return values
booldoSave()
protected
doSave(array<string|int, mixed> $values, int $lifetime) : array<string|int, mixed>|bool
Parameters
- $values : array<string|int, mixed>
- $lifetime : int
Return values
array<string|int, mixed>|boolcheckResultCode()
private
checkResultCode(mixed $result) : mixed
Parameters
- $result : mixed
decodeKey()
private
static decodeKey(string $key) : string
Parameters
- $key : string
Return values
stringencodeKey()
private
static encodeKey(string $key) : string
Parameters
- $key : string
Return values
stringgetClient()
private
getClient() : Memcached