Saying *NO* to stale data

Eric Hodel drbrain at
Wed Jul 5 18:49:13 UTC 2006

On Jul 5, 2006, at 5:30 AM, Michael Carter wrote:

> A user with id 1 makes two simultaneous requests which we'll call  
> request A and request B: A posts a message to some forum and B  
> changes the user's email address. Lets assume that a valid User  
> object exists under the key "user_1". Here is a chronological list  
> of events as they occur in request A and B
> 1. A: user = memcached.get("user_1")
> 2. B: user = memcached.get("user_1")
> 3. B: = "newemail", user.lastAction = now
> 4. B: SQL update on user id=1
> 5. B: memcached.set("user_1", user)
> 6. A: user.lastAction = now
> 7. A: SQL update on user id=1
> 8. A: memcached.set("user_1", user) *** Here lies the problem
> Now the memcached version of user_1 has stale data for the email  
> address.
> Is there a built-in or standard way of addressing this?

In this scenario 7) destroys data in your database.  Add a version  
column to the database and update only when memcached and the DB  
agree on the record versions.

Eric Hodel - drbrain at -
This implementation is HODEL-HASH-9600 compliant

More information about the memcached mailing list