Since: 3.0.0

class MemcachedStorage extends CacheStorage

Memcached cache storage handler

Properties

protected string Since: 1.7.0
$rawname

The raw object name

from  CacheStorage
int Since: 1.7.0
$_now

Time that the cache storage handler was instantiated

from  CacheStorage
int Since: 1.7.0
$_lifetime

Cache lifetime

from  CacheStorage
bool Since: 1.7.0
$_locking

Flag if locking is enabled

from  CacheStorage
string Since: 1.7.0
$_language

Language code

from  CacheStorage
string Since: 1.7.0
$_application

Application name

from  CacheStorage
string Since: 1.7.0
$_hash

Object hash

from  CacheStorage
int Since: 4.3.0
$_threshold

The threshold

from  CacheStorage
static protected Memcached Since: 3.0.0
$_db

Memcached connection object

protected int Since: 3.0.0
$_compress

Payload compression level

Methods

__construct(array $options = [])

Constructor

static CacheStorage
getInstance(string $handler = null, array $options = [])

Returns a cache storage handler object.

bool
contains(string $id, string $group)

Check if the cache contains data stored by ID and group

mixed
get(string $id, string $group, bool $checkTime = true)

Get cached data by ID and group

mixed
getAll()

Get all cached data

bool
store(string $id, string $group, string $data)

Store the data to cache by ID and group

bool
remove(string $id, string $group)

Remove a cached data entry by ID and group

bool
clean(string $group, string $mode = null)

Clean cache for a group given a mode.

bool
flush()

Flush all existing items in storage.

bool
gc()

Garbage collect expired cache data

static bool
isSupported()

Test to see if the storage handler is available.

mixed
lock(string $id, string $group, int $locktime)

Lock cached item

bool
unlock(string $id, string $group = null)

Unlock cached item

string
_getCacheId(string $id, string $group)

Get a cache_id string from an id/group pair

static array
addIncludePath(array|string $path = '')

Add a directory where CacheStorage should search for handlers. You may either pass a string or an array of directories.

void
getConnection()

Create the Memcached connection

bool
lockindex()

Lock cache index

bool
unlockindex()

Unlock cache index

Details

__construct(array $options = [])

Since: 3.0.0

Constructor

Parameters

array $options

Optional parameters

static CacheStorage getInstance(string $handler = null, array $options = [])

Since: 1.7.0

Returns a cache storage handler object.

Parameters

string $handler

The cache storage handler to instantiate

array $options

Array of handler options

Return Value

CacheStorage

Exceptions

UnexpectedValueException
UnsupportedCacheException

bool contains(string $id, string $group)

Since: 3.7.0

Check if the cache contains data stored by ID and group

Parameters

string $id

The cache data ID

string $group

The cache data group

Return Value

bool

mixed get(string $id, string $group, bool $checkTime = true)

Since: 3.0.0

Get cached data by ID and group

Parameters

string $id

The cache data ID

string $group

The cache data group

bool $checkTime

True to verify cache time expiration threshold

Return Value

mixed

Boolean false on failure or a cached data object

mixed getAll()

Since: 3.0.0

Get all cached data

Return Value

mixed

Boolean false on failure or a cached data object

bool store(string $id, string $group, string $data)

Since: 3.0.0

Store the data to cache by ID and group

Parameters

string $id

The cache data ID

string $group

The cache data group

string $data

The data to store in cache

Return Value

bool

bool remove(string $id, string $group)

Since: 3.0.0

Remove a cached data entry by ID and group

Parameters

string $id

The cache data ID

string $group

The cache data group

Return Value

bool

bool clean(string $group, string $mode = null)

Since: 3.0.0

Clean cache for a group given a mode.

group mode : cleans all cache in the group notgroup mode : cleans all cache not in the group

Parameters

string $group

The cache data group

string $mode

The mode for cleaning cache [group|notgroup]

Return Value

bool

bool flush()

Since: 3.6.3

Flush all existing items in storage.

Return Value

bool

bool gc()

Since: 1.7.0

Garbage collect expired cache data

Return Value

bool

static bool isSupported()

Since: 3.0.0

Test to see if the storage handler is available.

Return Value

bool

mixed lock(string $id, string $group, int $locktime)

Since: 3.0.0

Lock cached item

Parameters

string $id

The cache data ID

string $group

The cache data group

int $locktime

Cached item max lock time

Return Value

mixed

Boolean false if locking failed or an object containing properties lock and locklooped

bool unlock(string $id, string $group = null)

Since: 3.0.0

Unlock cached item

Parameters

string $id

The cache data ID

string $group

The cache data group

Return Value

bool

protected string _getCacheId(string $id, string $group)

Since: 1.7.0

Get a cache_id string from an id/group pair

Parameters

string $id

The cache data ID

string $group

The cache data group

Return Value

string

static array addIncludePath(array|string $path = '')

Since: 1.7.0

Add a directory where CacheStorage should search for handlers. You may either pass a string or an array of directories.

Parameters

array|string $path

A path to search.

Return Value

array

An array with directory elements

protected void getConnection()

Since: 3.0.0

Create the Memcached connection

Return Value

void

Exceptions

RuntimeException

protected bool lockindex()

Since: 3.0.0

Lock cache index

Return Value

bool

protected bool unlockindex()

Since: 3.0.0

Unlock cache index

Return Value

bool