concurrencymemcachedupdatesconsistency

How are concurrent updates handled in Memcached?


My understanding is that Memcached is lockless (in its default configuration), such that no client can impede any other client's operation. If that is the case, then how does Memcached handle two or more clients attempting to update the same object at the same time?

How does Memcached handle multiple versions of an object? Simply take the one whose update finished last and evict the other versions from the cache? Is the database actively invalidating objects cached on a Memcached server?


Solution

  • Memcached hold only last version of object. If you get, modify and put you have no guarantee that the put applies to the same value as the get. You could use CAS operations (gets, cas) if you need to synchronize.