Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strategy/pattern to prevent lost update / race conditions on GAE / memcache

Example:

  1. Process A - gets the latest version of an entity from memcache
  2. Process B - gets the latest version of an entity from memcache
  3. Process A - makes some update to the entity retrieved in (1) and then puts in db/memcache
  4. Process B - makes some update to the entity retrieved in (2) and then puts in db/memcache

Update 3. is lost.

What strategy/pattern can be used to prevent this?

like image 513
HorseloverFat Avatar asked Apr 04 '13 07:04

HorseloverFat


1 Answers

You probably want to use cas and gets commands:

https://code.google.com/p/memcached/wiki/NewCommands#cas

EDIT GAE memcache is actually compatible with memcached. Here's the reference from GAE:

https://developers.google.com/appengine/docs/python/memcache/clientclass#Client_cas

and final note:

https://developers.google.com/appengine/docs/python/memcache/clientclass#Memcached_compatibility

like image 136
freakish Avatar answered Oct 16 '22 02:10

freakish