Expiring memcache via regex

780 Views Asked by At

I'm using memcache in my rails app. I want to say

expire all the entries with keys like 'foo-123-*'

Where * is any string. Of course, no memcache distribution supports this directly (right?) because it's built to be simple and fast so it doesn't have indexes.

There are a couple projects that sort of address this, by keeping a local list of keys:

But in keeping the list in memory… that list can become out of sync between application instances… so it's not reliable.

Has this problem been solved in another way? Am I missing a common solution?

1

There are 1 best solutions below

0
On

as you said, query memcached like you want is not possible... but here is a php example i found that returns key list

http://snipt.org/xtP

it sends

  • "stats items"

and than iterate returned items and sends

  • "stats cachedump 42 100"

42 is item number, 100 is number of items to return

then you can iterate through returned keys and delete keys that you don't need any more.

(but this is an ugly workaround anyway...)