(Google AppEngine) Memcache Lock Entry

Posted by Friedrich on Stack Overflow See other posts from Stack Overflow or by Friedrich
Published on 2010-02-11T15:00:09Z Indexed on 2010/03/31 23:03 UTC
Read the original article Hit count: 424

Hi,

i need a locking in memcache. Since all operations are atomic that should be an easy task. My idea is to use a basic spin-lock mechanism. So every object that needs locking in memcache gets a lock object, which will be polled for access.

// pseudo code
// try to get a lock
int lock;
do
{
  lock = Memcache.increment("lock", 1);
}
while(lock != 1)

// ok we got the lock
// do something here

// and finally unlock
Memcache.put("lock", 0);

How does such a solution perform? Do you have a better idea how to lock a memcache object?

Best regards,

Friedrich Schick

© Stack Overflow or respective owner

Related posts about memcached

Related posts about google-app-engine