Caching and Race Status

I use memcache (not memcached) and I can have 10,000 requests at the same time as the cache. Which can cause a race condition, so I used this code http://terrychay.com/article/keeping-memcache-consistent.shtml to get the locks and set the key.

Now, from the registration, I saw that while one request A is waiting in the cache, another request B can complete the data sampling and is placed in the cache, so there is no request point A to wait and overwrite the data.

So, I thought there was one solution: while the request is waiting for a lock, it checks to see if the data was in the key. If it is there, than return data from the key, and not update it. Can anyone think of any suggestions? Will there be a key check while waiting for a lock to crack the memcache server?

+4
source share
1 answer

I don’t think it cost a lot to redo the lock code. Once you have a lock, you can just get , and if there is data, clear the lock and just return the data without getting into the database.

Doing this should also reduce the overall wait time.

+1
source

All Articles