Saying *NO* to stale data
drbrain at segment7.net
Wed Jul 5 19:12:35 UTC 2006
On Jul 5, 2006, at 12:08 PM, Michael Carter wrote:
>> > 1. A: user = memcached.get("user_1")
>> > 2. B: user = memcached.get ("user_1")
>> > 3. B: user.email = "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.
> I don't follow you. the column lastAction is just for the purpose
> of the example, but I intended it to mean the datetime that the
> user last did something. number 7 would just do: update users set
> lastAction=now where id=1; leaving all the other data intact.
And what happens when the user updates the same column twice (say
Eric Hodel - drbrain at segment7.net - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant
More information about the memcached