How to remove key range in memcached (using Dalli + RoR)

I run Ruby on Rails and use the Dalli gem to access memcached.

Question: how do I delete a key range (not a few, but a range) for something like: delete all memcached entries with a key that starts with "USERINFO", in other words, how can I use wildcards to delete a key range?

+4
source share
2 answers

You should take a look at Rails.cache.delete_matched: http://apidock.com/rails/ActiveSupport/Cache/Store/delete_matched

What you want is theoretically:

Rails.cache.delete_matched /^USERINFO/

0
source

Short answer: no, and you do not want to do this.

The dalli driver and memcached support the removal of several keys with one command from the box and for good reason. Because memcached locates cached values ​​by hashing a key in a production environment with multiple cache nodes, the delete_matched operation should scan all nodes that look for keys that could potentially match. This defeats the key goal of memcached , which is performance.

There are several implementations that extend dalli and promise to provide a deleted_matched implementation. They all seem to be a compromise for the convenience of programmers, so use them with caution. A look at the sources of these gems before using them is a good start.


Related Questions Can I get / find Memcached keys with a prefix?

0
source

Source: https://habr.com/ru/post/1391262/