Memcached storage engine for CakePHP, using the memcached extension
MIT License
This is an alternative memcached cache engine to the memcache engine shipped by default with cakePhp. Default one uses the memcache extension, whereas this one uses the memcached extension. (notice the d)
Igbinary is the big win of the memcached extension.
Igbinary is a drop in replacement for the standard php serializer. Instead of time and space consuming textual representation, igbinary stores php data structures in a compact binary form. Savings are significant when using memcached or similar memory based storages for serialized data. You can expect about 50% reduction in storage requirement and speed is at least on par with the standard PHP serializer. Specific numbers depend on your data, of course.
see https://github.com/phadej/igbinary and some benchmark
As of CakePHP 2.5, the memcached engine will be included in the core by default. No installation required.
[Manual]
app/Plugin
Memcached
[GIT Submodule]
In your app directory type:
git submodule add -b master git://github.com/kamisama/CakePHP-Memcached-Engine.git Plugin/kamisama/Memcached
git submodule init
git submodule update
[GIT Clone]
In your Plugin
directory type:
git clone -b master git://github.com/kamisama/CakePHP-Memcached-Engine.git Memcached
[Composer]
Add kamisama/cakephp-memcached-engine to your composer dependencies, then run
composer install
You need to enable the plugin your app/Config/bootstrap.php
file:
CakePlugin::load('Memcached');
If you are already using CakePlugin::loadAll();
, then this is not necessary.
Add this line in the head of your core.php:
App::uses('MemcachedEngine', 'Memcached.Lib/Cache/Engine');
You can then use it in your cache configuration:
Cache::config('default', array('engine' => 'Memcached'));
Since defining cache engine in a plugin is not supported yet on these version, you have to :
Lib/Cache/Engine
directory to the Lib/Cache/Engine
directory (create it if needed) in your app
folder.You need to enable the plugin your app/Config/bootstrap.php
file:
CakePlugin::load('Memcached');
If you are already using CakePlugin::loadAll();
, then this is not necessary.
Cache::config('default', array('engine' => 'Memcached'));
Cache::config('default', array('engine' => 'Memcached'));
The memcached cache engine can take the following options:
Cache::config('router', array(
# Usual options
'engine' => 'Memcached',
'prefix' => 'mc_',
'duration' => '+7 days', // Expires in 7 days, from now
'servers' => array(
'127.0.0.1', // Default port 11211
'127.0.0.1:11212' // Or you can specify the port
)
# Memcached options
'compress' => false,
'persistent' => false,
'login' => null,
'password => null,
'serialize' => 'php'
));
Default: true
Compress the cached data. Unlike memcache, memcached can increment/decrement compressed keys
Default: false
Use a persistent connection to the memcached server. To enable, set persistent
to an unique string, to identify the connection. All configurations using the same persistent value will share a single underlying connection.
Default: null
The memcached server credidentials, if using SASL for authentication.
Memcached need to be compiled with SASL support, else it'll throw a CacheException
.
Default: php
The engine used to serialize the data.
Available serializer supported by memcached:
The memcached extension is by default compiled with the php serializer. To use the other serializer, the memcached extension must be compiled with the appropriate options. Refer to Memcached documentation.
Using an invalid or not supported serializer engine will throw a CacheException
.
igbinary is the recommended serializer.
Binary protocol is temporary disabled due to a Memcached issue with increment/decrement
####Ver 0.12 (2013-10-06)
####Ver 0.11 (2013-09-19)
serializer
setting to serialize
persistent_id
setting with persitent
, which now takes a string as argument####Ver 0.10 (2013-09-18)
####Ver 0.9 (2013-09-04)
####Ver 0.8 (2013-09-04)
NOTE: As of CakePHP 2.5, MemcachedEngine v0.8 will be included into the core.
####Ver 0.7 (2013-08-26)
####Ver 0.6 (2013-08-26)
Memcached::getAllKeys()
to manage cache clearing####Ver 0.5 (2013-08-26)
####Ver 0.4 (2013-08-18)
####Ver 0.3 (2012-08-29)
####Ver 0.2 (2012-03-22)
Cache::clear()
This plugin is released under the MIT licence