Namespacing
Memcached does not natively support namespaces or tags.
It's difficult to support this natively as you cannot atomically expire the namespaces across all of your servers without adding quite a bit of complication.
Simulating Namespaces with Key Prefixes
Using a coordinated key prefix, you can create a virtual namespace that spans your entire memcached cluster. The prefix can be stored in your configuration and changed manually, or stored in an external key.Deleting By Namespace
Given a user and all his related keys, you want a one-stop switch to invalidate all of their cache entries at the same time.Using namespacing, you would set up a tertiary key with a version number inside it. You end up doing an extra round trip to memcached to figure the namespace.
user_prefix = memcli:get('user_namespace:' . user_id)
bio_data = memcli:get(user_prefix . user_id . 'bio')
Invalidating the namespace simply requires editing that key. Your application will no longer request the old keys, and they will eventually fall off the end of the LRU and be reclaimed.
Careful in how you implement the prefix. You'll want to use add so you don't blow away an existing namespace. You'll also want to initialize it to something with a low probability of coming up again.
Using namespaces or prefixes only controls the keys stored/retrieved. There is no security within memcached, and therefore no way to enforce that a particular client only accesses keys with a particular namespace. Namespaces are only useful as a method of identifying data and preventing corruption of key/value pairs.