Class MemcachedEngine

Memcached storage engine for cache. Memcached has some limitations in the amount of control you have over expire times far in the future. See MemcachedEngine::write() for more information.

Main advantage of this Memcached engine over the memcached engine is support of binary protocol, and igbibnary serialization (if memcached extension compiled with --enable-igbinary) Compressed keys can also be incremented/decremented

This cache engine requires at least ext/memcached version 2.0

CacheEngine
Extended by MemcachedEngine
Package: Cake\Cache\Engine
Copyright: Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
License: MIT License
Location: Cake/Cache/Engine/MemcachedEngine.php

Properties summary

Inherited Properties

Method Summary

  • Parses the server address into the host/port. Handles both IPv6 and IPv4 addresses and Unix sockets

  • _setOptions() protected
    Settings the memcached instance
  • add() public

    Write data for key into cache if it doesn't exist already. When using memcached as your cache engine remember that the Memcached pecl extension does not support cache expiry times greater than 30 days in the future. Any duration greater than 30 days will be treated as never expiring. If it already exists, it fails and returns false.

  • clear() public
    Delete all keys from the cache
  • clearGroup() public

    Increments the group value to simulate deletion of all keys under a group old values will remain in storage until they expire.

  • decrement() public
    Decrements the value of an integer cached key
  • delete() public
    Delete a key from the cache
  • groups() public

    Returns the group value for each of the configured groups If the group initial value was not found, then it initializes the group accordingly.

  • increment() public
    Increments the value of an integer cached key
  • init() public
    Initialize the Cache Engine
  • read() public
    Read a key from the cache
  • write() public

    Write data for key into cache. When using memcached as your cache engine remember that the Memcached PECL extension does not support cache expiry times greater than 30 days in the future. Any duration greater than 30 days will be treated as never expiring.

Method Detail

_parseServerString()source protected

_parseServerString( string $server )

Parses the server address into the host/port. Handles both IPv6 and IPv4 addresses and Unix sockets

Parameters

string $server
The server address string.

Returns

array
Array containing host, port

_setOptions()source protected

_setOptions( )

Settings the memcached instance

Throws

CacheException
when the Memcached extension is not built with the desired serializer engine

add()source public

add( string $key , mixed $value , integer $duration )

Write data for key into cache if it doesn't exist already. When using memcached as your cache engine remember that the Memcached pecl extension does not support cache expiry times greater than 30 days in the future. Any duration greater than 30 days will be treated as never expiring. If it already exists, it fails and returns false.

Parameters

string $key
Identifier for the data.
mixed $value
Data to be cached.
integer $duration
How long to cache the data, in seconds.

Returns

boolean
True if the data was successfully cached, false on failure.

Link

http://php.net/manual/en/memcached.add.php

Overrides

CacheEngine::add()

clear()source public

clear( boolean $check )

Delete all keys from the cache

Parameters

boolean $check

If true no deletes will occur and instead CakePHP will rely on key TTL values.

Returns

boolean

True if the cache was successfully cleared, false otherwise. Will also return false if you are using a binary protocol.


clearGroup()source public

clearGroup( string $group )

Increments the group value to simulate deletion of all keys under a group old values will remain in storage until they expire.

Parameters

string $group
The group to clear.

Returns

boolean
success

Overrides

CacheEngine::clearGroup()

decrement()source public

decrement( string $key , integer $offset 1 )

Decrements the value of an integer cached key

Parameters

string $key
Identifier for the data
integer $offset optional 1
How much to subtract

Returns

New
decremented value, false otherwise

Throws

CacheException
when you try to decrement with compress = true

delete()source public

delete( string $key )

Delete a key from the cache

Parameters

string $key
Identifier for the data

Returns

boolean
True if the value was successfully deleted, false if it didn't exist or couldn't be removed

groups()source public

groups( )

Returns the group value for each of the configured groups If the group initial value was not found, then it initializes the group accordingly.

Returns

array

Overrides

CacheEngine::groups()

increment()source public

increment( string $key , integer $offset 1 )

Increments the value of an integer cached key

Parameters

string $key
Identifier for the data
integer $offset optional 1
How much to increment

Returns

New
incremented value, false otherwise

Throws

CacheException
when you try to increment with compress = true

init()source public

init( array $settings array() )

Initialize the Cache Engine

Called automatically by the cache frontend To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());

Parameters

array $settings optional array()
array of setting for the engine

Returns

boolean
True if the engine has been successfully initialized, false if not

Throws

CacheException
when you try use authentication without Memcached compiled with SASL support

Overrides

CacheEngine::init()

read()source public

read( string $key )

Read a key from the cache

Parameters

string $key
Identifier for the data

Returns

mixed
The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it

write()source public

write( string $key , mixed $value , integer $duration )

Write data for key into cache. When using memcached as your cache engine remember that the Memcached PECL extension does not support cache expiry times greater than 30 days in the future. Any duration greater than 30 days will be treated as never expiring.

Parameters

string $key
Identifier for the data
mixed $value
Data to be cached
integer $duration
How long to cache the data, in seconds

Returns

boolean
True if the data was successfully cached, false on failure

See

http://php.net/manual/en/memcache.set.php

Methods inherited from CacheEngine

gc()source public

gc( integer $expires null )

Garbage collection

Permanently remove all expired and deleted data

Parameters

integer $expires optional null
[optional] An expires timestamp, invalidating all data before.

key()source public

key( string $key )

Generates a safe key for use with cache engine storage engines.

Parameters

string $key
the key passed over

Returns

mixed
string $key or false

settings()source public

settings( )

Cache Engine settings

Returns

array
settings

Properties detail

$_Memcachedsource

protected Memcache

memcached wrapper.

null

$_serializerssource

protected array

List of available serializer engines

Memcached must be compiled with json and igbinary support to use these engines

array(
    'igbinary' => Memcached::SERIALIZER_IGBINARY,
    'json' => Memcached::SERIALIZER_JSON,
    'php' => Memcached::SERIALIZER_PHP
)

$settingssource

public array

Settings

  • servers = string or array of memcached servers, default => 127.0.0.1. If an array MemcacheEngine will use them as a pool.
    • compress = boolean, default => false
    • persistent = string The name of the persistent connection. All configurations using the same persistent value will share a single underlying connection.
    • serialize = string, default => php. The serializer engine used to serialize data. Available engines are php, igbinary and json. Beside php, the memcached extension must be compiled with the appropriate serializer support.
    • options - Additional options for the memcached client. Should be an array of option => value. Use the Memcached::OPT_* constants as keys.
array()

© 2005–2017 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/2.10/class-MemcachedEngine.html