问题
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:
- https://github.com/defconomicron/dalli-store-extensions
- https://github.com/jkassemi/memcache-store-extensions
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:
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...)
来源:https://stackoverflow.com/questions/11998762/expiring-memcache-via-regex