Short answer is, no and you don't want to do that.
The dalli
gem nor memcached
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, a delete_matched
operation would need to scan across all the nodes looking for keys that potentially match. This defeats a key goal of memcached
which is performance.
There exist several implementations that extend dalli
and promise to provide an implementation of deleted_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?