Memcached
extends AbstractAdapter
in package
implements
AvailableSpaceCapableInterface, FlushableInterface, TotalSpaceCapableInterface
Interfaces, Classes, Traits and Enums
Table of Contents
- $capabilities : null|Capabilities
- Capabilities of this adapter
- $capabilityMarker : null|object
- Marker to change capabilities
- $eventHandles : array<string|int, mixed>
- Event handles of this adapter
- $events : null|EventManagerInterface
- The used EventManager if any
- $initialized : bool
- Has this instance be initialized
- $namespacePrefix : string
- The namespace prefix
- $options : mixed
- options
- $pluginRegistry : SplObjectStorage
- The plugin registry
- $resourceId : null|string
- The memcached resource id
- $resourceManager : null|MemcachedResourceManager
- The memcached resource manager
- __construct() : mixed
- Constructor
- __destruct() : void
- Destructor
- addItem() : bool
- Add an item.
- addItems() : array<string|int, mixed>
- Add multiple items.
- addPlugin() : AbstractAdapter
- Register a plugin
- checkAndSetItem() : bool
- Set an item only if token matches
- decrementItem() : int|bool
- Decrement an item.
- decrementItems() : array<string|int, mixed>
- Decrement multiple items.
- flush() : bool
- Flush the whole storage
- getAvailableSpace() : int|float
- Get available space in bytes
- getCaching() : bool
- Get caching enabled.
- getCapabilities() : Capabilities
- Get capabilities of this adapter
- getEventManager() : EventManagerInterface
- Get the event manager
- getItem() : mixed
- Get an item.
- getItems() : array<string|int, mixed>
- Get multiple items.
- getMetadata() : array<string|int, mixed>|bool
- Get metadata of an item.
- getMetadatas() : array<string|int, mixed>
- Get multiple metadata
- getOptions() : MemcachedOptions
- Get options.
- getPluginRegistry() : SplObjectStorage
- Return registry of plugins
- getTotalSpace() : int|float
- Get total space in bytes
- hasItem() : bool
- Test if an item exists.
- hasItems() : array<string|int, mixed>
- Test multiple items.
- hasPlugin() : bool
- Check if a plugin is registered
- incrementItem() : int|bool
- Increment an item.
- incrementItems() : array<string|int, mixed>
- Increment multiple items.
- removeItem() : bool
- Remove an item.
- removeItems() : array<string|int, mixed>
- Remove multiple items.
- removePlugin() : AbstractAdapter
- Unregister an already registered plugin
- replaceItem() : bool
- Replace an existing item.
- replaceItems() : array<string|int, mixed>
- Replace multiple existing items.
- setCaching() : AbstractAdapter
- Enable/Disable caching.
- setItem() : bool
- Store an item.
- setItems() : array<string|int, mixed>
- Store multiple items.
- setOptions() : Memcached
- Set options.
- touchItem() : bool
- Reset lifetime of an item
- touchItems() : array<string|int, mixed>
- Reset lifetime of multiple items.
- expirationTime() : int
- Get expiration time by ttl
- getExceptionByResultCode() : mixed
- Generate exception based of memcached result code
- getMemcachedResource() : Memcached
- Initialize the internal memcached resource
- internalAddItem() : bool
- Add an item.
- internalAddItems() : array<string|int, mixed>
- Internal method to add multiple items.
- internalCheckAndSetItem() : bool
- Internal method to set an item only if token matches
- internalDecrementItem() : int|bool
- Internal method to decrement an item.
- internalDecrementItems() : array<string|int, mixed>
- Internal method to decrement multiple items.
- internalGetCapabilities() : Capabilities
- Internal method to get capabilities of this adapter
- internalGetItem() : mixed
- Internal method to get an item.
- internalGetItems() : array<string|int, mixed>
- Internal method to get multiple items.
- internalGetMetadata() : array<string|int, mixed>|bool
- Internal method to get metadata of an item.
- internalGetMetadatas() : array<string|int, mixed>
- Get metadata of multiple items
- internalHasItem() : bool
- Internal method to test if an item exists.
- internalHasItems() : array<string|int, mixed>
- Internal method to test multiple items.
- internalIncrementItem() : int|bool
- Internal method to increment an item.
- internalIncrementItems() : array<string|int, mixed>
- Internal method to increment multiple items.
- internalRemoveItem() : bool
- Internal method to remove an item.
- internalRemoveItems() : array<string|int, mixed>
- Internal method to remove multiple items.
- internalReplaceItem() : bool
- Internal method to replace an existing item.
- internalReplaceItems() : array<string|int, mixed>
- Internal method to replace multiple existing items.
- internalSetItem() : bool
- Internal method to store an item.
- internalSetItems() : array<string|int, mixed>
- Internal method to store multiple items.
- internalTouchItem() : bool
- Internal method to reset lifetime of an item
- internalTouchItems() : array<string|int, mixed>
- Internal method to reset lifetime of multiple items.
- normalizeKey() : void
- Validates and normalizes a key
- normalizeKeys() : void
- Validates and normalizes multiple keys
- normalizeKeyValuePairs() : void
- Validates and normalizes an array of key-value pairs
- triggerException() : mixed
- Trigger an exception event
- triggerPost() : mixed
- Triggers the PostEvent and return the result value.
- triggerPre() : ResponseCollection
- Trigger a pre event and return the event response collection
Properties
$capabilities
Capabilities of this adapter
protected
null|Capabilities
$capabilities
= null
$capabilityMarker
Marker to change capabilities
protected
null|object
$capabilityMarker
$eventHandles
Event handles of this adapter
protected
array<string|int, mixed>
$eventHandles
= []
$events
The used EventManager if any
protected
null|EventManagerInterface
$events
= null
$initialized
Has this instance be initialized
protected
bool
$initialized
= false
$namespacePrefix
The namespace prefix
protected
string
$namespacePrefix
= ''
$options
options
protected
mixed
$options
$pluginRegistry
The plugin registry
protected
SplObjectStorage
$pluginRegistry
Registered plugins
$resourceId
The memcached resource id
protected
null|string
$resourceId
$resourceManager
The memcached resource manager
protected
null|MemcachedResourceManager
$resourceManager
Methods
__construct()
Constructor
public
__construct([null|array<string|int, mixed>|Traversable|MemcachedOptions $options = null ]) : mixed
Parameters
- $options : null|array<string|int, mixed>|Traversable|MemcachedOptions = null
Tags
Return values
mixed —__destruct()
Destructor
public
__destruct() : void
detach all registered plugins to free event handles of event manager
Return values
void —addItem()
Add an item.
public
addItem(string $key, mixed $value) : bool
Parameters
- $key : string
- $value : mixed
Tags
Return values
bool —addItems()
Add multiple items.
public
addItems(array<string|int, mixed> $keyValuePairs) : array<string|int, mixed>
Parameters
- $keyValuePairs : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Array of not stored keys
addPlugin()
Register a plugin
public
addPlugin(PluginInterface $plugin[, int $priority = 1 ]) : AbstractAdapter
Parameters
- $plugin : PluginInterface
- $priority : int = 1
Tags
Return values
AbstractAdapter —Provides a fluent interface
checkAndSetItem()
Set an item only if token matches
public
checkAndSetItem(mixed $token, string $key, mixed $value) : bool
It uses the token received from getItem() to check if the item has changed before overwriting it.
Parameters
- $token : mixed
- $key : string
- $value : mixed
Tags
Return values
bool —decrementItem()
Decrement an item.
public
decrementItem(string $key, int $value) : int|bool
Parameters
- $key : string
- $value : int
Tags
Return values
int|bool —The new value on success, false on failure
decrementItems()
Decrement multiple items.
public
decrementItems(array<string|int, mixed> $keyValuePairs) : array<string|int, mixed>
Parameters
- $keyValuePairs : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Associative array of keys and new values
flush()
Flush the whole storage
public
flush() : bool
Return values
bool —getAvailableSpace()
Get available space in bytes
public
getAvailableSpace() : int|float
Return values
int|float —getCaching()
Get caching enabled.
public
getCaching() : bool
Alias of getWritable and getReadable.
Tags
Return values
bool —getCapabilities()
Get capabilities of this adapter
public
getCapabilities() : Capabilities
Tags
Return values
Capabilities —getEventManager()
Get the event manager
public
getEventManager() : EventManagerInterface
Return values
EventManagerInterface —getItem()
Get an item.
public
getItem(string $key[, bool &$success = null ][, mixed &$casToken = null ]) : mixed
Parameters
- $key : string
- $success : bool = null
- $casToken : mixed = null
Tags
Return values
mixed —Data on success, null on failure
getItems()
Get multiple items.
public
getItems(array<string|int, mixed> $keys) : array<string|int, mixed>
Parameters
- $keys : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Associative array of keys and values
getMetadata()
Get metadata of an item.
public
getMetadata(string $key) : array<string|int, mixed>|bool
Parameters
- $key : string
Tags
Return values
array<string|int, mixed>|bool —Metadata on success, false on failure
getMetadatas()
Get multiple metadata
public
getMetadatas(array<string|int, mixed> $keys) : array<string|int, mixed>
Parameters
- $keys : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Associative array of keys and metadata
getOptions()
Get options.
public
getOptions() : MemcachedOptions
Tags
Return values
MemcachedOptions —getPluginRegistry()
Return registry of plugins
public
getPluginRegistry() : SplObjectStorage
Return values
SplObjectStorage —getTotalSpace()
Get total space in bytes
public
getTotalSpace() : int|float
Return values
int|float —hasItem()
Test if an item exists.
public
hasItem(string $key) : bool
Parameters
- $key : string
Tags
Return values
bool —hasItems()
Test multiple items.
public
hasItems(array<string|int, mixed> $keys) : array<string|int, mixed>
Parameters
- $keys : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Array of found keys
hasPlugin()
Check if a plugin is registered
public
hasPlugin(PluginInterface $plugin) : bool
Parameters
- $plugin : PluginInterface
Return values
bool —incrementItem()
Increment an item.
public
incrementItem(string $key, int $value) : int|bool
Parameters
- $key : string
- $value : int
Tags
Return values
int|bool —The new value on success, false on failure
incrementItems()
Increment multiple items.
public
incrementItems(array<string|int, mixed> $keyValuePairs) : array<string|int, mixed>
Parameters
- $keyValuePairs : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Associative array of keys and new values
removeItem()
Remove an item.
public
removeItem(string $key) : bool
Parameters
- $key : string
Tags
Return values
bool —removeItems()
Remove multiple items.
public
removeItems(array<string|int, mixed> $keys) : array<string|int, mixed>
Parameters
- $keys : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Array of not removed keys
removePlugin()
Unregister an already registered plugin
public
removePlugin(PluginInterface $plugin) : AbstractAdapter
Parameters
- $plugin : PluginInterface
Tags
Return values
AbstractAdapter —Provides a fluent interface
replaceItem()
Replace an existing item.
public
replaceItem(string $key, mixed $value) : bool
Parameters
- $key : string
- $value : mixed
Tags
Return values
bool —replaceItems()
Replace multiple existing items.
public
replaceItems(array<string|int, mixed> $keyValuePairs) : array<string|int, mixed>
Parameters
- $keyValuePairs : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Array of not stored keys
setCaching()
Enable/Disable caching.
public
setCaching(bool $flag) : AbstractAdapter
Alias of setWritable and setReadable.
Parameters
- $flag : bool
Tags
Return values
AbstractAdapter —Provides a fluent interface
setItem()
Store an item.
public
setItem(string $key, mixed $value) : bool
Parameters
- $key : string
- $value : mixed
Tags
Return values
bool —setItems()
Store multiple items.
public
setItems(array<string|int, mixed> $keyValuePairs) : array<string|int, mixed>
Parameters
- $keyValuePairs : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Array of not stored keys
setOptions()
Set options.
public
setOptions(array<string|int, mixed>|Traversable|MemcachedOptions $options) : Memcached
Parameters
- $options : array<string|int, mixed>|Traversable|MemcachedOptions
Tags
Return values
Memcached —touchItem()
Reset lifetime of an item
public
touchItem(string $key) : bool
Parameters
- $key : string
Tags
Return values
bool —touchItems()
Reset lifetime of multiple items.
public
touchItems(array<string|int, mixed> $keys) : array<string|int, mixed>
Parameters
- $keys : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Array of not updated keys
expirationTime()
Get expiration time by ttl
protected
expirationTime() : int
Some storage commands involve sending an expiration value (relative to an item or to an operation requested by the client) to the server. In all such cases, the actual value sent may either be Unix time (number of seconds since January 1, 1970, as an integer), or a number of seconds starting from current time. In the latter case, this number of seconds may not exceed 606024*30 (number of seconds in 30 days); if the expiration value is larger than that, the server will consider it to be real Unix time value rather than an offset from current time.
Return values
int —getExceptionByResultCode()
Generate exception based of memcached result code
protected
getExceptionByResultCode(int $code) : mixed
Parameters
- $code : int
Tags
Return values
mixed —getMemcachedResource()
Initialize the internal memcached resource
protected
getMemcachedResource() : Memcached
Return values
Memcached —internalAddItem()
Add an item.
protected
internalAddItem(string &$normalizedKey, mixed &$value) : bool
Parameters
- $normalizedKey : string
- $value : mixed
Tags
Return values
bool —internalAddItems()
Internal method to add multiple items.
protected
internalAddItems(array<string|int, mixed> &$normalizedKeyValuePairs) : array<string|int, mixed>
Parameters
- $normalizedKeyValuePairs : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Array of not stored keys
internalCheckAndSetItem()
Internal method to set an item only if token matches
protected
internalCheckAndSetItem(mixed &$token, string &$normalizedKey, mixed &$value) : bool
Parameters
- $token : mixed
- $normalizedKey : string
- $value : mixed
Tags
Return values
bool —internalDecrementItem()
Internal method to decrement an item.
protected
internalDecrementItem(string &$normalizedKey, int &$value) : int|bool
Parameters
- $normalizedKey : string
- $value : int
Tags
Return values
int|bool —The new value on success, false on failure
internalDecrementItems()
Internal method to decrement multiple items.
protected
internalDecrementItems(array<string|int, mixed> &$normalizedKeyValuePairs) : array<string|int, mixed>
Parameters
- $normalizedKeyValuePairs : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Associative array of keys and new values
internalGetCapabilities()
Internal method to get capabilities of this adapter
protected
internalGetCapabilities() : Capabilities
Return values
Capabilities —internalGetItem()
Internal method to get an item.
protected
internalGetItem(string &$normalizedKey[, bool &$success = null ][, mixed &$casToken = null ]) : mixed
Parameters
- $normalizedKey : string
- $success : bool = null
- $casToken : mixed = null
Tags
Return values
mixed —Data on success, null on failure
internalGetItems()
Internal method to get multiple items.
protected
internalGetItems(array<string|int, mixed> &$normalizedKeys) : array<string|int, mixed>
Parameters
- $normalizedKeys : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Associative array of keys and values
internalGetMetadata()
Internal method to get metadata of an item.
protected
internalGetMetadata(string &$normalizedKey) : array<string|int, mixed>|bool
Parameters
- $normalizedKey : string
Tags
Return values
array<string|int, mixed>|bool —Metadata on success, false on failure
internalGetMetadatas()
Get metadata of multiple items
protected
internalGetMetadatas(array<string|int, mixed> &$normalizedKeys) : array<string|int, mixed>
Parameters
- $normalizedKeys : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Associative array of keys and metadata
internalHasItem()
Internal method to test if an item exists.
protected
internalHasItem(string &$normalizedKey) : bool
Parameters
- $normalizedKey : string
Tags
Return values
bool —internalHasItems()
Internal method to test multiple items.
protected
internalHasItems(array<string|int, mixed> &$normalizedKeys) : array<string|int, mixed>
Parameters
- $normalizedKeys : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Array of found keys
internalIncrementItem()
Internal method to increment an item.
protected
internalIncrementItem(string &$normalizedKey, int &$value) : int|bool
Parameters
- $normalizedKey : string
- $value : int
Tags
Return values
int|bool —The new value on success, false on failure
internalIncrementItems()
Internal method to increment multiple items.
protected
internalIncrementItems(array<string|int, mixed> &$normalizedKeyValuePairs) : array<string|int, mixed>
Parameters
- $normalizedKeyValuePairs : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Associative array of keys and new values
internalRemoveItem()
Internal method to remove an item.
protected
internalRemoveItem(string &$normalizedKey) : bool
Parameters
- $normalizedKey : string
Tags
Return values
bool —internalRemoveItems()
Internal method to remove multiple items.
protected
internalRemoveItems(array<string|int, mixed> &$normalizedKeys) : array<string|int, mixed>
Parameters
- $normalizedKeys : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Array of not removed keys
internalReplaceItem()
Internal method to replace an existing item.
protected
internalReplaceItem(string &$normalizedKey, mixed &$value) : bool
Parameters
- $normalizedKey : string
- $value : mixed
Tags
Return values
bool —internalReplaceItems()
Internal method to replace multiple existing items.
protected
internalReplaceItems(array<string|int, mixed> &$normalizedKeyValuePairs) : array<string|int, mixed>
Parameters
- $normalizedKeyValuePairs : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Array of not stored keys
internalSetItem()
Internal method to store an item.
protected
internalSetItem(string &$normalizedKey, mixed &$value) : bool
Parameters
- $normalizedKey : string
- $value : mixed
Tags
Return values
bool —internalSetItems()
Internal method to store multiple items.
protected
internalSetItems(array<string|int, mixed> &$normalizedKeyValuePairs) : array<string|int, mixed>
Parameters
- $normalizedKeyValuePairs : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Array of not stored keys
internalTouchItem()
Internal method to reset lifetime of an item
protected
internalTouchItem(string &$normalizedKey) : bool
Parameters
- $normalizedKey : string
Tags
Return values
bool —internalTouchItems()
Internal method to reset lifetime of multiple items.
protected
internalTouchItems(array<string|int, mixed> &$normalizedKeys) : array<string|int, mixed>
Parameters
- $normalizedKeys : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Array of not updated keys
normalizeKey()
Validates and normalizes a key
protected
normalizeKey(string &$key) : void
Parameters
- $key : string
Tags
Return values
void —normalizeKeys()
Validates and normalizes multiple keys
protected
normalizeKeys(array<string|int, mixed> &$keys) : void
Parameters
- $keys : array<string|int, mixed>
Tags
Return values
void —normalizeKeyValuePairs()
Validates and normalizes an array of key-value pairs
protected
normalizeKeyValuePairs(array<string|int, mixed> &$keyValuePairs) : void
Parameters
- $keyValuePairs : array<string|int, mixed>
Tags
Return values
void —triggerException()
Trigger an exception event
protected
triggerException(string $eventName, ArrayObject $args, mixed &$result, Exception $exception) : mixed
If the ExceptionEvent has the flag "throwException" enabled throw the exception after trigger else return the result.
Parameters
- $eventName : string
- $args : ArrayObject
- $result : mixed
- $exception : Exception
Tags
Return values
mixed —triggerPost()
Triggers the PostEvent and return the result value.
protected
triggerPost(string $eventName, ArrayObject $args, mixed &$result) : mixed
Parameters
- $eventName : string
- $args : ArrayObject
- $result : mixed
Return values
mixed —triggerPre()
Trigger a pre event and return the event response collection
protected
triggerPre(string $eventName, ArrayObject $args) : ResponseCollection
Parameters
- $eventName : string
- $args : ArrayObject
Return values
ResponseCollection —All handler return values