Suppose you want to keep an list of the last 10 visitors to your site in memcache.
Every time that someone accesses your site, you want to push them onto an array and shift off the first visitor in the array.
Of course, a potential problem is that multiple visitors could be overwriting and reading this array at the same time, possibly tripping each other up. There isn't an atomic push/shift in memcache, of course.
Possible inconsistency scenario with 2 near-simultaneous user accesses:
- User A gets array from memcache
- User B gets array from memcache
- User A modifies array (change will be lost)
- User B modifies array
- User A stores array in memcache
- User B stores array in memcache (will overwrite A's change in step 3)
How can you accomplish something like this correctly using memcache?