Hi David One way to solve this is to make the external version ID part of the key. This way, all writes will be ok, but when you read the item you have to know the version ID so you can read the latest version always, assuming this information is available to all readers.
Another way is to do it in two layers so that you store the external version ID in memcache as well so that for the key "key" you store the version id, and for the key "key" + versionid, you store the actual item. This way all readers will have the version id just by knowing the key. The drawback though is that you have to update the version id in memcache as well whenever it changes externally. You also require more trips to the cache server, but that's probably negligible compared to the usual speedup that you gain from using memcached in the first place. But external CAS ids are not possible as far as I know, which would be the best solution. /Henrik On Wed, Apr 1, 2009 at 01:37, David Raccah <rac...@gmail.com> wrote: > > Hello, > > I was wondering if there is the possibility (in the works or one that > I missed) to update objects in the cache with a version ID that is > external to memcached - but is sure to be increasing in value? So say > you have multiple > writers to the system that are updating an item in the cache whose key > is 123. What we would like is the ability for the clients to set the > value for 123 along with an external version ID, so that we will > minimize collisions, or worse invalid updates. > > This is great for write behind cache techniques. So if I read data > from a DB and then add or update the item into the memcached with the > item's key along with a unique increasing version number like a rowid > or some sequence ID from the DB. So: > > Client 1 writes version 1 of item 123 into DB > Client 2 writes version 2 of item 123 into DB > Client 1 is in the middle of a GC for 1 minute - please do not ask why > - just an example of a slowdown that exceeds back off time (another > synch mechanism used around here) > Client 2 writes version 2 into memcached > Client1 wakes up and overwrites version 2 with version 1 of item 123. > > Yes there are many ways around this - like serializing all updates to > memcached and keeping track of the last version number - etc. They > all work, but make things more complex. > > So, please excuse me if it exists and I missed it, or if this has been > bashed or spoken about in previous threads. > > Thanks! > David >