I am running Ruby on Rails and am using the Dalli gem to access memcached.
Question: how do I delete a range of keys (not multiple, but a range) for something like: delete all memcached entries with a key that begins with "USERINFO", in other words, how can I use wildcards to delete a range of keys?
Short answer is, no and you don't want to do that.
The
dalli
gem normemcached
support deleting multiple keys with a single command out of the box and for good reason. Since memcached determines the location of cached values by hashing the key, in a production environment with multiple cache nodes, adelete_matched
operation would need to scan across all the nodes looking for keys that potentially match. This defeats a key goal ofmemcached
which is performance.There exist several implementations that extend
dalli
and promise to provide an implementation ofdeleted_matched
. These all appear to trade-off programmer convenience over performance so use them with caution. Taking a look at sources of these gems before using them is a good start.Related questions Is it possible to get/search Memcached keys by a prefix?