MemcachedCache
extends Cache
in package
Class MemcachedCache.
Table of Contents
- $autoClose : bool
- $configs : array<string|int, mixed>
- Memcached Cache handler configurations.
- $debugCollector : CacheCollector
- $defaultTtl : int
- The default Time To Live value.
- $logger : Logger|null
- The Logger instance if is set.
- $memcached : Memcached
- $prefix : string|null
- Keys prefix.
- $serializer : Serializer
- Data serializer.
- __construct() : mixed
- MemcachedCache constructor.
- __destruct() : mixed
- close() : bool
- Close the cache storage.
- decrement() : int
- Decrements the value of one item.
- delete() : bool
- Deletes one item from the cache storage.
- deleteMulti() : array<string, bool>
- Deletes multi items from the cache storage.
- flush() : bool
- Flush the cache storage.
- get() : mixed
- Gets one item from the cache storage.
- getDefaultTtl() : int
- Get the default Time To Live value in seconds.
- getMemcached() : Memcached|null
- Get Memcached instance or null.
- getMulti() : array<string, mixed>
- Gets multi items from the cache storage.
- increment() : int
- Increments the value of one item.
- isAutoClose() : bool
- set() : bool
- Sets one item to the cache storage.
- setAutoClose() : static
- setDebugCollector() : static
- setDefaultTtl() : static
- Set the default Time To Live value in seconds.
- setMemcached() : static
- Set custom Memcached instance.
- setMulti() : array<string, bool>
- Sets multi items to the cache storage.
- addDebugDelete() : bool
- addDebugFlush() : bool
- addDebugGet() : mixed
- addDebugSet() : bool
- connect() : void
- getValue() : mixed
- initialize() : void
- Initialize Cache handlers and configurations.
- log() : void
- makeTtl() : int
- Make the Time To Live value.
- renderKey() : string
- serialize() : string
- setConfigs() : static
- setSerializer() : static
- unserialize() : mixed
- validateConfigs() : void
Properties
$autoClose
protected
bool
$autoClose
= true
$configs
Memcached Cache handler configurations.
protected
array<string|int, mixed>
$configs
= ['servers' => [['host' => '127.0.0.1', 'port' => 11211, 'weight' => 0]], 'options' => [\Memcached::OPT_BINARY_PROTOCOL => true]]
$debugCollector
protected
CacheCollector
$debugCollector
$defaultTtl
The default Time To Live value.
protected
int
$defaultTtl
= 60
Used when set methods has the $ttl param as null.
$logger
The Logger instance if is set.
protected
Logger|null
$logger
$memcached
protected
Memcached
$memcached
$prefix
Keys prefix.
protected
string|null
$prefix
= null
$serializer
Data serializer.
protected
Serializer
$serializer
Methods
__construct()
MemcachedCache constructor.
public
__construct([Memcached|array<string, mixed>|null $configs = [] ][, string|null $prefix = null ][, Serializer|string $serializer = Serializer::PHP ][, Logger|null $logger = null ]) : mixed
Parameters
- $configs : Memcached|array<string, mixed>|null = []
-
Driver specific configurations. Set null to not initialize or a custom Memcached object.
- $prefix : string|null = null
-
Keys prefix
- $serializer : Serializer|string = Serializer::PHP
-
Data serializer
- $logger : Logger|null = null
-
Logger instance
Return values
mixed —__destruct()
public
__destruct() : mixed
Return values
mixed —close()
Close the cache storage.
public
close() : bool
Return values
bool —TRUE on success, otherwise FALSE
decrement()
Decrements the value of one item.
public
decrement(string $key[, int $offset = 1 ][, int|null $ttl = null ]) : int
Parameters
- $key : string
-
The item name
- $offset : int = 1
-
The value to decrement
- $ttl : int|null = null
-
The Time To Live for the item or null to use the default
Return values
int —The current item value
delete()
Deletes one item from the cache storage.
public
delete(string $key) : bool
Parameters
- $key : string
-
the item name
Return values
bool —TRUE if the item was deleted, FALSE if fail to delete
deleteMulti()
Deletes multi items from the cache storage.
public
deleteMulti(array<int, string> $keys) : array<string, bool>
Parameters
- $keys : array<int, string>
-
List of items names to be deleted
Return values
array<string, bool> —associative array with key names and respective delete status
flush()
Flush the cache storage.
public
flush() : bool
Return values
bool —TRUE if all items are deleted, otherwise FALSE
get()
Gets one item from the cache storage.
public
get(string $key) : mixed
Parameters
- $key : string
-
The item name
Return values
mixed —The item value or null if not found
getDefaultTtl()
Get the default Time To Live value in seconds.
public
getDefaultTtl() : int
Return values
int —getMemcached()
Get Memcached instance or null.
public
getMemcached() : Memcached|null
Tags
Return values
Memcached|null —getMulti()
Gets multi items from the cache storage.
public
getMulti(array<int, string> $keys) : array<string, mixed>
Parameters
- $keys : array<int, string>
-
List of items names to get
Return values
array<string, mixed> —associative array with key names and respective values
increment()
Increments the value of one item.
public
increment(string $key[, int $offset = 1 ][, int|null $ttl = null ]) : int
Parameters
- $key : string
-
The item name
- $offset : int = 1
-
The value to increment
- $ttl : int|null = null
-
The Time To Live for the item or null to use the default
Return values
int —The current item value
isAutoClose()
public
isAutoClose() : bool
Tags
Return values
bool —set()
Sets one item to the cache storage.
public
set(string $key, mixed $value[, int|null $ttl = null ]) : bool
Parameters
- $key : string
-
The item name
- $value : mixed
-
The item value
- $ttl : int|null = null
-
The Time To Live for the item or null to use the default
Return values
bool —TRUE if the item was set, FALSE if fail to set
setAutoClose()
public
setAutoClose(bool $autoClose) : static
Parameters
- $autoClose : bool
-
True to enable auto close, false to disable
Tags
Return values
static —setDebugCollector()
public
setDebugCollector(CacheCollector $debugCollector) : static
Parameters
- $debugCollector : CacheCollector
Return values
static —setDefaultTtl()
Set the default Time To Live value in seconds.
public
setDefaultTtl(int $seconds) : static
Parameters
- $seconds : int
-
An integer greater than zero
Return values
static —setMemcached()
Set custom Memcached instance.
public
setMemcached(Memcached $memcached) : static
Parameters
- $memcached : Memcached
Tags
Return values
static —setMulti()
Sets multi items to the cache storage.
public
setMulti(array<string, mixed> $data[, int|null $ttl = null ]) : array<string, bool>
Parameters
- $data : array<string, mixed>
-
Associative array with key names and respective values
- $ttl : int|null = null
-
The Time To Live for all the items or null to use the default
Return values
array<string, bool> —associative array with key names and respective set status
addDebugDelete()
protected
addDebugDelete(string $key, float $start, bool $status) : bool
Parameters
- $key : string
- $start : float
- $status : bool
Return values
bool —addDebugFlush()
protected
addDebugFlush(float $start, bool $status) : bool
Parameters
- $start : float
- $status : bool
Return values
bool —addDebugGet()
protected
addDebugGet(string $key, float $start, mixed $value) : mixed
Parameters
- $key : string
- $start : float
- $value : mixed
Return values
mixed —addDebugSet()
protected
addDebugSet(string $key, int|null $ttl, float $start, mixed $value, bool $status) : bool
Parameters
- $key : string
- $ttl : int|null
- $start : float
- $value : mixed
- $status : bool
Return values
bool —connect()
protected
connect() : void
Return values
void —getValue()
protected
getValue(string $key) : mixed
Parameters
- $key : string
Return values
mixed —initialize()
Initialize Cache handlers and configurations.
protected
initialize() : void
Return values
void —log()
protected
log(string $message[, LogLevel $level = LogLevel::ERROR ]) : void
Parameters
- $message : string
- $level : LogLevel = LogLevel::ERROR
Return values
void —makeTtl()
Make the Time To Live value.
protected
makeTtl(int|null $seconds) : int
Parameters
- $seconds : int|null
-
TTL value or null to use the default
Return values
int —The input $seconds or the $defaultTtl as integer
renderKey()
protected
renderKey(string $key) : string
Parameters
- $key : string
Return values
string —serialize()
protected
serialize(mixed $value) : string
Parameters
- $value : mixed
Tags
Return values
string —setConfigs()
protected
setConfigs(array<string, mixed> $configs) : static
Parameters
- $configs : array<string, mixed>
Tags
Return values
static —setSerializer()
protected
setSerializer(Serializer|string $serializer) : static
Parameters
- $serializer : Serializer|string
Tags
Return values
static —unserialize()
protected
unserialize(string $value) : mixed
Parameters
- $value : string
Return values
mixed —validateConfigs()
protected
validateConfigs() : void