Memcache Configuration

Last Updated: 28 Aug 2017

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.

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,
            '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 hostname of the Memcache server where the memcache server is listening for connections.
  • 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. Having this enabled can make retry_interval values other than 0 behave unpredictably with sessions (see Session Handling for more info).
  • 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:

  • compression_threshold: controls the minimum size before automatic compression. By default, this is set to 20000 bytes.
  • compression_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 given a weight of 1. You can configure multiple hosts on these services. Weights are used to define the number of buckets assigned to each host, hosts with larger numbers of buckets will have a higher probability of being selected. In this example we give 'mc2' a higher chance of being used than 'mc1':

'session_handling'     => Array('mc1' => 1, 'mc2' => 2)

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).

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.

5-0-0_memcache-cache-storage.png
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.

If persistent is TRUE and retry_interval is greater than 0 the memcache PECL will unpredictably keep the sessions host offline after any communication failure occurs, as such if there's only one session host available it's recommended to set the retry_interval to 0 and leave persistent as TRUE. If there's more than one session host having retry_interval as 0 would cause Matrix to run slowly whenever a memcached host is down, so in that case it's recommended to set persistent to FALSE instead.

Once you have configured the memcache.inc file, you can enable Memcache session handling 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

Previous Chapter Next Chapter

The Latest

Let Us Know What You Think

Let us know if you spot any errors or if you have any ideas on how we can improve the Matrix Community Website.

Contact Squiz for Demo

Let us show you the true power of Squiz Matrix by giving you a personalised demonstration.