Memcached Service

Memcached is an in-memory key-value store used for caching by many web applications and frameworks. It is available in Helion Stackato as a service which can be shared by application instances.

Using the Service

As with other data services, the location and port of the memcached service is exposed to the application via environment variables: STACKATO_SERVICES, VCAP_SERVICES, or MEMCACHED_URL.

The easiest way to connect an application to a Memcached service is to use the MEMCACHED_URL environment variable. It contains the location and port of the service created for the application. For example:

MEMCACHED_URL=10.13.0.6:11000

Warning

The memcached binary bundled with Helion Stackato does not support SASL authentication, so the memcached_node sasl_enabled setting should remain set to false (default).

Django Example using Memcached

The Django GTD sample application uses the simpler VCAP_SERVICES method for connecting to the Memcached service without authentication.

The relevant configuration in this example:

  1. Specifies the location of memcached using the MEMCACHED_URL in settings.py:

    CACHES = {
        'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': os.getenv('MEMCACHED_URL'),
        }
    }
    
  2. Adds the cache to middleware classes:

    MIDDLEWARE_CLASSES = (
        'django.middleware.cache.UpdateCacheMiddleware',
        'django.middleware.cache.FetchFromCacheMiddleware',
        ...
    )
    
  3. Adds the python-memcached module and a Memcached service in manifest.yml:

    requirements:
        pip:
        - python-memcached
        ...
    services:
        memcached-gtd: memcached
        ...