Caching Application Data

The flexible runtime environment provides a standard memcached service.

Accessing the Memcached Service

The flexible runtime environment adds two environment variables for talking to memcached:


Install a memcached client library

In order to use memcached, use any standard client library that supports the memcached text protocol.

We recommend using xmemcached. Add it to your pom.xml file:


Here is a code example showing memcached in action:

// [...]

import net.rubyeye.xmemcached.MemcachedClient;
import net.rubyeye.xmemcached.MemcachedClientBuilder;
import net.rubyeye.xmemcached.XMemcachedClientBuilder;
import net.rubyeye.xmemcached.exception.MemcachedException;
import net.rubyeye.xmemcached.utils.AddrUtil;

// [...]

String addr = System.getenv().get("MEMCACHE_PORT_11211_TCP_ADDR");
if (addr == null) {
   addr = "localhost";

String port = System.getenv().get("MEMCACHE_PORT_11211_TCP_PORT");
if (port == null) {
   port = "11211";
MemcachedClientBuilder builder = new XMemcachedClientBuilder(
       AddrUtil.getAddresses(addr + ":" + port));
MemcachedClient client =;

// [...]

client.set("entry", 0, "hello");
answer = client.get("entry");

// [...]

Testing memcached locally

If you are testing your app locally, you need to install a memcached daemon in your OS:


  1. Use the memcached package.

    For Debian and Ubuntu derivatives:

    apt-get install memcached

    For Red Hat, CentOS, and Fedora, use yum:

    yum install memcached

    For Linux Arch:

    pacman -S memcached
  2. Run it as a daemon (or check systemd for an automatic startup):

    memcached -d

Mac OS X

  1. Install Homebrew:

    ruby -e "$(curl -fsSL"
  2. Install memcached:

    brew install memcached
  3. Run it as a daemon:

    memcached -d
  4. Create a database:

    curl --header 'Authorization: Bearer [ACCESS_TOKEN]' \
    --header 'Content-Type: application/json' \


  1. Build your own memcached. Alternatively, you can download freeware binaries.

  2. Run it as a daemon:

    memcached -d

Send feedback about...

App Engine flexible environment for Java docs