« Return to Thread: How to delete lots of related keys at once

Re: How to delete lots of related keys at once

by Bugzilla from webb.clint@gmail.com :: Rate this Message:

Reply to Author | View in Thread


Why is everyone using memcache for the SQL query as a key?  That is what the query cache on your database is for.  You gain very little doing it this way, except now you have to manage the invalidation yourself, which the query-cache does for you.

Anyway, you can set your keys with an expiry so that they dissapear after a certain time and can be regenerated.  Each site is different, but for any kind of data that could change, and you dont have an easy way of identifying the affected keys when it does change, then you should give it an expiry time.  That way, eventually, changes will be replicated thru the cache as the keys expire and regenerate.

Namespaces probably isnt what you are looking for.  It merely adds a string to the begining of the key.  Useful if you are using the same memcache cluster for multiple applications, but thats about it.  If you normally use a key of "Article:id=5", but use a namespace of "Supersite-" then internally your key will now be "Supersite-Article:id=5".

I use namespaces for my sitelogging (web instances write logging info to cache using incremented keys, external process pulls those log entries out of cache and puts them in a file).  I have multiple sites use the same memcache cluster, and the same piece of code, but the sites logs are kept seperate, and copied out to different files, because when the different sites (and external processing script) connect to the cache, they use different namespaces.

On 8/3/07, Jarom Severson <j.severson@...> wrote:
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.

thanks in advance.

Jay




--
"Be excellent to each other"

 « Return to Thread: How to delete lots of related keys at once