How to delete a keys in memcached with regex (using Dalli+RoR).

5.7k Views Asked by At

How to delete a keys in memcached with regex (using Dalli+Rails)

  def expire_all
   expire_fragment(Regexp.new("/customers/customers"))
   expire_fragment(Regexp.new("/customers/customers\/"))
   expire_fragment(Regexp.new("/agreements/agreements"))
   expire_fragment(Regexp.new("/agreements/agreements\/"))
  end

Not working with memcached. Any Ideas?

2

There are 2 best solutions below

2
On BEST ANSWER

install gem dalli-store-extensions https://github.com/defconomicron/dalli-store-extensions

In the Sweeper

expire_fragment /#{Regexp.escape(restaurant.id)}\/stocks*/
0
On

Memcached isn't able to iterate over its keys, so regexp expiration won't work. See the docs.

Take a look at this for a potential workaround, though it's labor intensive.