Memcached (Object cache)

Memcached is a simple in-memory object store well-suited for application level caching.

See the Memcached documentation for more information.

Both Memcached and Redis can be used for application caching. As a general rule, Memcached is simpler and thus more widely supported while Redis is more robust. recommends using Redis if possible but Memcached is fully supported if an application favors that cache service.

Supported versions

  • 1.4


The format exposed in the $PLATFORM_RELATIONSHIPS environment variable:

    "service": "memcached",
    "ip": "",
    "hostname": "",
    "cluster": "rjify4yjcwxaa-master-7rqtwti",
    "host": "memcached.internal",
    "rel": "memcached",
    "scheme": "memcached",
    "type": "memcached:1.4",
    "port": 11211

Usage example

In your .platform/services.yaml:

    type: memcached:1.4

Now add a relationship in your file:

    cache: "memcached:memcached"

If you are using PHP, configure the relationship and enable the [PHP memcached extension](/languages/ in your ``.  (Note that the `memcached` extension requires `igbinary` and `msgpack` as well, but those will be enabled automatically.)

        - memcached
For Python you will need to include a dependency for a Memcached library, either via your requirements.txt file or a global dependency.  As a global dependency you would add the following to ``:

       python-memcached: '*'

You can then use the service in a configuration file of your application with something like:



use Platformsh\ConfigReader\Config;

// Create a new config object to ease reading the environment variables.
// You can alternatively use getenv() yourself.
$config = new Config();

// Get the credentials to connect to the Memcached service.
$credentials = $config->credentials('memcached');

try {
    // Connecting to Memcached server.
    $memcached = new Memcached();
    $memcached->addServer($credentials['host'], $credentials['port']);
    $memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, true);

    $key = "Deploy day";
    $value = "Friday";

    // Set a value.
    $memcached->set($key, $value);

    // Read it back.
    $test = $memcached->get($key);

    printf('Found value <strong>%s</strong> for key <strong>%s</strong>.', $test, $key);

} catch (Exception $e) {
    print $e->getMessage();
const Memcached = require('memcached');
const config = require("platformsh-config").config();
const { promisify } = require('util');

exports.usageExample = async function() {

    const credentials = config.credentials('memcached');

    let client = new Memcached(`${}:${credentials.port}`);

    // The MemcacheD client is not Promise-aware, so make it so.
    const memcachedGet = promisify(client.get).bind(client);
    const memcachedSet = promisify(client.set).bind(client);

    let key = 'Deploy-day';
    let value = 'Friday';

    // Set a value.
    await memcachedSet(key, value, 10);

    // Read it back.
    let test = await memcachedGet(key);

    let output = `Found value <strong>${test}</strong> for key <strong>${key}</strong>.`;

    return output;

import pymemcache
from platformshconfig import Config

def usage_example():

    # Create a new Config object to ease reading the environment variables.
    # You can alternatively use os.environ yourself.
    config = Config()

    # Get the credentials to connect to the Memcached service.
    credentials = config.credentials('memcached')

        # Try connecting to Memached server.
        memcached = pymemcache.Client((credentials['host'], credentials['port']))
        memcached.set('Memcached::OPT_BINARY_PROTOCOL', True)

        key = "Deploy_day"
        value = "Friday"

        # Set a value.
        memcached.set(key, value)

        # Read it back.
        test = memcached.get(key)

        return 'Found value <strong>{0}</strong> for key <strong>{1}</strong>.'.format(test.decode("utf-8"), key)

    except Exception as e:
        return e

Accessing Memcached directly

To access the Memcached service directly you can simply use netcat as Memcached does not have a dedicated client tool. Assuming your Memcached relationship is named cache, the host name and port number obtained from PLATFORM_RELATIONSHIPS would be cache.internal and 11211. Open an SSH session and access the Memcached server as follows:

netcat cache.internal 11211