Memcache Configuration
Memcache can be configured on a Squiz Matrix system as an alternative to Matrix Cache.
The asset locking and cache storage enhancements using Memcache require the memcache PECL module, version 2.0.0 to be installed.
The Memcache services configurable on Squiz Matrix include cache storage, session handling, asset locking, and Deja Vu, an extension of Memcache, providing memory storage for asset objects, metadata values and locale strings.
Bookmarks to the headings on this page:
Configuring the Memcache Hosts
Memcache host servers can be configured within the system's memcache.inc file (~/data/private/conf/memcache.inc). The default layout of the hosts array section of this file is shown below:
'hosts' => Array(
'mc1' => Array (
'host' => '',
'port' => 11211,
// If unsure, leave these alone.
'persistent' => TRUE,
'weight' => 1,
'timeout' => 1,
'retry_interval' => 15,
'status' => TRUE,
),
),
Multiple hosts can be defined within this array. The parameters available for configuration are as follows:
- host: the path to the Memcache server.
- port: the port of the Memcache server. By default, this is set to 11211 (default port).
- persistent: controls the use of a persistent Memcache connection. By default, this is set to TRUE.
- weight: the number of buckets to create for this server. By default, this is set to 1.
- timeout: the value (in seconds) which will be used for connecting to the server. By default, this is set to 1.
- retry_interval: controls how often a failed server will be automatically retried. By default, this is set to 15 seconds. Setting this parameter to -1 will disable automatic retry.
- status: controls if the server should be flagged as online. By default, this is set to TRUE, meaning that the server is considered online.
For more information on these parameters, refer to the PHP: Memcache::addServer Manual.
The set compression threshold section of the memcache.inc file allows you to configure automatic compression of large values. The parameters available for configuration are as follows:
- threshold: controls the minimum size before automatic compression. By default, this is set to 20000 bytes.
- min_saving: specifies the minimum saving before storing compressed. This value must be between 0 and 1. By default, this is set to 0.2, giving a minimum 20% compression saving.
For more information on these parameters, refer to the PHP: Memcache::setCompressionThreshold Manual.
Setting Up the Memcache Services
Squiz Matrix offers four Memcache services that can be configured within the system's memcache.inc file (~/data/private/conf/memcache.inc) once Memcache host servers have been configured. The default layout of the services section of the memcache.inc file is shown below:
'cache_manager' => Array('mc1' => 1),
'session_handling' => Array(),
'locking' => Array(),
'deja_vu' => Array(),
By default, the cache_manager service will be utilising the mc1 default host set up.
To configure hosts for these Memcache services, add the host server ID to the service array, as follows:
'session_handling' => Array('mc1' => 1)
In this example, the mc1 host server has been set to 1 (true). You can configure multiple hosts on these services. This is useful to create a fallback if the initial host cannot be reached or fails. This is achieved like so:
'session_handling' => Array('mc1' => 1, 'mc2' => 1)
Continue reading below for more information on the services available for Memcache.
Cache Manager
The Memcache cache_manager service allows you to store Matrix cache entries within Memcache rather than the default SQ_CACHE directory (specified in main.inc). Please note that clearing of Memcache-based Matrix cache cannot be done on an individual asset basis, due to the limitations of Memcache.
The cache storage system is fully optional for Memcache and is configured in the memcache.inc file. The default set up of this service is as follows:
'cache_manager' => Array('mc1' => 1)
Once you have configured the memcache.inc file, you can enable Memcache cache storage on the Details screen of the Cache Manager.

The Memcache Cache Storage option
In the Cache Storage Type field, select Memcache Cache Storage and click Commit. Memcache cache storage will now be enabled on your system, using the Memcache server settings specified in the memcache.inc file.
Session Handling
The Memcache session handler allows you to handle Matrix sessions within Memcache.
Session handling is fully optional for Memcache and is configured in the memcache.inc file. The default set up of this service is as follows:
'session_handling' => Array()
When multiple Memcache servers are used, only session fatal errors will be outputted to HTML; warnings and notices WILL NOT be logged. This will allow for a silent failover. You will need to monitor the operation of the Memcache servers independently.
Once you have configured the memcache.inc file, you can enable Memcache asset locking by setting the SQ_CONF_SESSION_HANDLER value in the system’s main.inc file, as follows:
Define(‘SQ_CONF_SESSION_HANDLER’, ‘memcache’);
Memcache session handling will now be enabled on your system, using the Memcache server settings specified in the memcache.inc file.
Locking
Matrix lock entries can be stored within Memcache, rather than the default SQ_LOCK database table. Please note, however, that forcibly acquiring locks, the mass changing of lock ownership and notifications of active lock ownership are not available under Memcache asset locking, due to the limitations of Memcache.
The asset locking system is fully optional for Memcache and is configured in the memcache.inc file. The default set up of this service is as follows:
'locking' => Array()
Once you have configured the memcache.inc file, you can enable Memcache asset locking by setting the SQ_CONF_LOCKING_METHOD value in the system’s main.inc file, as follows:
Define(‘SQ_CONF_LOCKING_METHOD’, ‘memcache’);
Memcache asset locking will now be enabled on your system, using the Memcache server settings specified in the memcache.inc file.
Deja Vu
Deja Vu is an extension of Memcache, providing memory storage for asset objects, metadata values and locale strings. It is designed to move common data loading into a more persistent memory, improving the scalability of sites.
Deja Vu should be setup with a separate Memcache instance to avoid causing issues with sessions or content caching. We also recommend that only large scale systems with aggressive cache expiry strategies implement the Deja Vu extension.
While cached page response times are generally acceptable under normal Memcache setups, users may experience large loading at frequent intervals due to aggressive cache expiration. Deja Vu combats these issues by using memory to store object, metadata and locale data.
Deja Vu is fully optional for Memcache and is configured in the memcache.inc file. The default set up of this service is as follows:
'deja_vu' => Array()
Once you have configured the memcache.inc file, you can enable Deja Vu using the dejavu_management.php script, as follows:
$ php scripts/dejavu_management.php -s <system_root> --enable
Deja Vu will now be enabled on your system, using the Memcache server settings specified in the memcache.inc file.
To disable Deja Vu, run the dejavu_management.php script, as follows:
$ php scripts/dejavu_management.php -s <system_root> --disable
$ php scripts/dejavu_management.php -s <system_root> --disable-force