jthijssen at noxlogic.nl
Fri Jan 20 10:47:40 UTC 2006
We're currently using memcached as part of a separate caching-class.
When we need data (for instance, products from a webshop), we check if
the data is found in the cache. If it's not there, we do a query and
then save the query-result into the (mem)cache which we probably would
store with a key like "<shopname>.article.<id>".
This works like a charm but has a major drawback: Let's say we want to
restore products from a previous backup. This means new articles would
be removed since they do not exist in the backup.
If we do a very quick deletion (say the sql-query "DELETE FROM ARTICLES
WHERE category_id=5"), we have troubles with the caching. The products
in there are not deleted, and there is no way of telling which articles
is in the cache. After deletion, we still see the articles because there
read from cache (as it should).
For this reason we save/update a housekeeping-table for each
database-table we save with memcached. Every time we insert or delete an
article from the cache, we have a separate array which basically tells
us which keys are stored in the memcache. This is of course a very
time/bandwidth consuming way of keeping track of data. But has the major
advantage that when deleting articles from the database, we don't need
to go over them 1 by 1, deleting the key from the cache etc etc.
I would like to know: Are there better ways to achieve the same without
the housekeeping-table hassle, and basically: how are you caching things
and what kind of data do you cache?
More information about the memcached