named cache "zones"

Christopher Gillett cgillett at
Wed Aug 3 15:29:29 PDT 2005

I've got several nearly-related and several unrelated applications
running - all sharing a huge cache that exists on a dozen-or-so nodes.
To get around namespace collision issues, I took a page from the
Java/Python world of module imports, and assigned top-level cache tags
to each application.  Within that namespace developers are free to use
additional tags to further stratify their worlds.

So a typical key in our cache might look like:

Where "cfs" is the top-level name, "slotmapping" is within the namespace
devised by the application developer, and the balance of the key is an
MD5 hash computed on the value that the developer wants to store.  Then
it's just a simple matter of concating the namespace discriminators
together with the rest of the key and you're all done.

So far we've had no incidents of namespace collisions.  The only thing
you need to be careful about is that cache access rights are unmanaged -
any application can void the entire cache including other namespaces via
flush_all(). This is only a problem in cases where you are not mapping
your cache to a backing store - we do that for a couple of high
performance applications that use memcache to maintain state
information, everything else is backed by MySQL.  My simple solution to
this was to modify the memcache client code we're using (the Python
version) and restrict the flush_all() method to certain users on certain
hosts.  That doesn't prevent malicious cache voids, but prevents silly
mistakes from becoming big problems.  And all that is only a problem if
you don't maintain a coherent backing store.

Since you said you're just starting to use memcached, let me plug
gratuitously and say it's been an extremely useful and super-elegant
solution to a number of problems I've been working on.  

Hope this helps,

Christopher Gillett
Compete, Inc.
Boston, Massachuetts USA

> -----Original Message-----
> From: memcached-bounces at 
> [mailto:memcached-bounces at] On Behalf Of Garth Patil
> Sent: Wednesday, August 03, 2005 5:27 PM
> To: memcached at
> Subject: named cache "zones"
> hi,
> i've just started using memcached with the java api (thanks 
> greg!), and i've looked around the archives for an answer to 
> this question, but haven't been able to find it.
> is there a way to create multiple named caches within a 
> single memcached process?
> for example, i'd like to have a few caches that have 
> potentially overlapping keys, but all stored in the same 
> memcached instance. other than just concatenating the cache 
> name to the key, is there a good way to do this in memcached?
> thanks,
> /garth

More information about the memcached mailing list