Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect and debug stale cache entries?

I am using memcached with PHP trying for heavy caching to avoid db-reads. I am invalidating the cache on an update (application invalidates). But, stale cache data is becoming a big issue. Mostly, this is due to bug in invalidation (invalidates wrong key OR forgetting to invalidate the cache entry on an UPDATE).

Is there any good method to detect/debug these type of bugs during development/production?

like image 215
Shameem Avatar asked Oct 27 '22 07:10

Shameem


1 Answers

The best thing to do is to put a wrapper function around mysql_query. Inside of that, just check if the query is an update or a delete to a cached table and parse out the keys that are being changed. This won't take long to write, is easy to test, and will prevent you from ever forgetting a cache invalidation again.

like image 137
twk Avatar answered Nov 14 '22 09:11

twk