pymemcache.fallback module

A client for falling back to older memcached servers when performing reads.

It is sometimes necessary to deploy memcached on new servers, or with a different configuration. In these cases, it is undesirable to start up an empty memcached server and point traffic to it, since the cache will be cold, and the backing store will have a large increase in traffic.

This class attempts to solve that problem by providing an interface identical to the Client interface, but which can fall back to older memcached servers when reads to the primary server fail. The approach for upgrading memcached servers or configuration then becomes:

  1. Deploy a new host (or fleet) with memcached, possibly with a new configuration.

  2. From your application servers, use FallbackClient to write and read from the new cluster, and to read from the old cluster when there is a miss in the new cluster.

  3. Wait until the new cache is warm enough to support the load.

  4. Switch from FallbackClient to a regular Client library for doing all reads and writes to the new cluster.

  5. Take down the old cluster.

Best Practices:

  • Make sure that the old client has “ignore_exc” set to True, so that it treats failures like cache misses. That will allow you to take down the old cluster before you switch away from FallbackClient.

class pymemcache.fallback.FallbackClient(caches)

Bases: object

__init__(caches)
add(key, value, expire=0, noreply=True)
append(key, value, expire=0, noreply=True)
cas(key, value, cas, expire=0, noreply=True)
close()

Close each of the memcached clients

decr(key, value, noreply=True)
delete(key, noreply=True)
flush_all(delay=0, noreply=True)
get(key)
get_many(keys)
gets(key)
gets_many(keys)
incr(key, value, noreply=True)
prepend(key, value, expire=0, noreply=True)
quit()
replace(key, value, expire=0, noreply=True)
set(key, value, expire=0, noreply=True)
stats()
touch(key, expire=0, noreply=True)