Documentation

MemcachedHandler extends BaseHandler
in package

Mamcached cache handler

Table of Contents

MAX_KEY_LENGTH  = PHP_INT_MAX
Maximum key length.
RESERVED_CHARACTERS  = '{}()/\@:'
Reserved characters that cannot be used in a key or tag.
$config  : array<string|int, mixed>
Memcached Configuration
$memcached  : Memcached|Memcache
The memcached object
$prefix  : string
Prefix to apply to cache keys.
__construct()  : mixed
Constructor.
__destruct()  : mixed
Class destructor
clean()  : bool
Will delete all items in the entire cache.
decrement()  : int|false
Performs atomic decrementation of a raw stored value.
delete()  : bool
Deletes a specific item from the cache store.
deleteMatching()  : mixed
Deletes items from the cache store matching a given pattern.
get()  : mixed
Attempts to fetch an item from the cache store.
getCacheInfo()  : array<string|int, mixed>|false
Returns information on the entire cache.
getMetaData()  : array<string|int, mixed>|false|null
Returns detailed information about the specific item in the cache.
increment()  : int|false
Performs atomic incrementation of a raw stored value.
initialize()  : mixed
Takes care of any handler-specific setup that must be done.
isSupported()  : bool
Determines if the driver is supported on this system.
remember()  : mixed
Get an item from the cache, or execute the given Closure and store the result.
save()  : bool
Saves an item to the cache store.
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.

public mixed RESERVED_CHARACTERS = '{}()/\@:'

From https://github.com/symfony/cache-contracts/blob/c0446463729b89dd4fa62e9aeecc80287323615d/ItemInterface.php#L43

Properties

$config

Memcached Configuration

protected array<string|int, mixed> $config = ['host' => '127.0.0.1', 'port' => 11211, 'weight' => 1, 'raw' => false]

$prefix

Prefix to apply to cache keys.

protected string $prefix

May not be used by all handlers.

Methods

__destruct()

Class destructor

public __destruct() : mixed

Closes the connection to Memcache(d) if present.

Return values
mixed

clean()

Will delete all items in the entire cache.

public clean() : bool
Return values
bool

Success or failure

decrement()

Performs atomic decrementation of a raw stored value.

public decrement(string $key[, int $offset = 1 ]) : int|false
Parameters
$key : string

Cache ID

$offset : int = 1

Step/value to increase by

Return values
int|false

delete()

Deletes a specific item from the cache store.

public delete(string $key) : bool
Parameters
$key : string

Cache item name

Return values
bool

Success or failure

deleteMatching()

Deletes items from the cache store matching a given pattern.

public deleteMatching(string $pattern) : mixed
Parameters
$pattern : string

Cache items glob-style pattern

Tags
throws
Exception
Return values
mixed

get()

Attempts to fetch an item from the cache store.

public get(string $key) : mixed
Parameters
$key : string

Cache item name

Return values
mixed

getCacheInfo()

Returns information on the entire cache.

public getCacheInfo() : array<string|int, mixed>|false

The information returned and the structure of the data varies depending on the handler.

Return values
array<string|int, mixed>|false

getMetaData()

Returns detailed information about the specific item in the cache.

public getMetaData(string $key) : array<string|int, mixed>|false|null
Parameters
$key : string

Cache item name.

Return values
array<string|int, mixed>|false|null

Returns null if the item does not exist, otherwise array<string, mixed> with at least the 'expire' key for absolute epoch expiry (or null). Some handlers may return false when an item does not exist, which is deprecated.

increment()

Performs atomic incrementation of a raw stored value.

public increment(string $key[, int $offset = 1 ]) : int|false
Parameters
$key : string

Cache ID

$offset : int = 1

Step/value to increase by

Return values
int|false

initialize()

Takes care of any handler-specific setup that must be done.

public initialize() : mixed
Return values
mixed

isSupported()

Determines if the driver is supported on this system.

public isSupported() : bool
Return values
bool

remember()

Get an item from the cache, or execute the given Closure and store the result.

public remember(string $key, int $ttl, Closure $callback) : mixed
Parameters
$key : string

Cache item name

$ttl : int

Time to live

$callback : Closure

Callback return value

Return values
mixed

save()

Saves an item to the cache store.

public save(string $key, mixed $value[, int $ttl = 60 ]) : bool
Parameters
$key : string

Cache item name

$value : mixed

The data to save

$ttl : int = 60

Time To Live, in seconds (default 60)

Return values
bool

Success or failure

validateKey()

Validates a cache key according to PSR-6.

public static validateKey(string $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 : string

The key to validate

$prefix : string = ''

Optional prefix to include in length calculations

Tags
throws
InvalidArgumentException

When $key is not valid

Return values
string

Search results