How to detect and debug obsolete cache entries?

I use memcached with PHP, trying to cache heavily to avoid db-reads. I will invalidate the cache during the upgrade (application is invalid). But outdated cache data is becoming a big problem. This is mainly due to an invalidation error (invalidates the wrong key or forgets to invalidate the cache entry in UPDATE).

Is there any good method to detect / debug these types of errors during development / production?

+5
source share
3 answers

The best thing to do is put the wrapper function in mysql_query. Inside this, just check if the query is an update or delete to a cached table and analyze the keys that are changing. It does not take much time to write, it is easy to verify, and it does not allow you to forget about the invalidation of the cache again.

+3
source

You can use the optimistic concurrency control, which includes adding another column to the table (timestamp or equivalent or just a simple int) and using it when performing updates. Here you can use it (in case plain int is a "version tag"):

update BlogPost set PublishedOn = :publishedOn, VersionTag = VersionTag + 1
where ID = :id and VersionTag = :versionTag

And provided that the timestamp is automatically updated by your DBMS, this is done with timestamps:

update BlogPost set PublishedOn = :publishedOn
where ID = :id and Timestamp = :timestamp
0

( ), : memcached , / , , ( ) .

, :

  • , (, )
  • , (script/ ). ,
0

All Articles