How to delete lots of related keys at once

K J sanbat at gmail.com
Wed Sep 19 14:02:25 UTC 2007


>
> My main confusion or concern with memcache is how to
> go about deleting a given set of keys in the
> cache. For instance, we probably have 10-15 pages on
> our site that hit the "articles" tables in our
> database. So, that right there would be 10-15 unique
> key/value pairs in memcache, assuming I store the
> query as the key, and the result set as the value. Now
> add on dynamic search strings, pagination, etc, and
> you've probably got 100 unique key/value pairs in
> memcache, all pertaining to articles.
>
> So my question is, if we want to make sure our site is
> never stale, then we need to invalidate all 100 of
> those keys if someone inserts a new article. Now I'm
> thinking I need to do a search in my keys to find all
> article related keys and invalidate them.
>
> Is the best way to do this then to store ANOTHER key
> value pair which essentially stores all the article
> related keys as its value? So that I can quickly and
> easily invalidate the 100 other keys?
>
> It seems like this might be what "namespaces" are for,
> but I can't understand the example given on the
> memcached FAG page.
>
> Any help and direction in this area would be much
> appreciated, or any other good articles I should read
> that talk about best practices, implementation
> techniques, etc.


I'm facing the same problem here.  From the responses I'm guessing that most
of you think it's better to cache each individual "article" and perhaps the
article titles for display.  Listings still hit the database directly.  The
only savings would be that the app wouldn't have to do another SQL to fetch
the article titles/links/data, as it can get it from the cache.

However, is there no way to cache these pages effectively?  For instance,
what if say I set a default expiration time for anything that's not on page
1.  Then whenever an article gets inserted, the first 10 pages are purged,
while pages 11 onwards are expired on their own.

What do you guys think of this solution?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.danga.com/pipermail/memcached/attachments/20070919/631cb760/attachment.html


More information about the memcached mailing list