5

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?

Ilhom
  • 144
  • 3
  • 12

2 Answers2

3

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.

x1a4
  • 19,417
  • 5
  • 40
  • 40
3

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

In the Sweeper

expire_fragment /#{Regexp.escape(restaurant.id)}\/stocks*/
Ilhom
  • 144
  • 3
  • 12
  • 2
    dalli-store-extensions uses a local memory cache, so it can get out of synch between app instances. (i think that's the issue). see my question here http://stackoverflow.com/questions/11998762/expiring-memcache-via-regex – John Bachir Aug 17 '12 at 01:43
  • 1
    There are also significant performance issues with constantly serializing and deserializing a key set when writing and deleting keys. – Vadim Feb 12 '16 at 15:44