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.

Include a memcache client library in your requirements.txt file:


Use memcached in your code like this:

memcache_addr = os.environ.get('MEMCACHE_PORT_11211_TCP_ADDR', 'localhost')
memcache_port = os.environ.get('MEMCACHE_PORT_11211_TCP_PORT', 11211)
memcache_client = MemcacheClient((memcache_addr, int(memcache_port)))

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 Python docs