trouble expiring fragment via regex #97

letronje opened this Issue Oct 20, 2011 · 6 comments

5 participants


here's how my cache_action is defined :

caches_action :index, :cache_path => {
user = current_user
user.nil? ? "/home/index" : "home/index/#{}"

in my sweeper,

I would like to expire everything under "home/index/"

def after_update

redis-cli monitor shows the following keys command that it gets :
"del" "views/home/index" ( expected and working fine )
"keys" "(?-mix:.home\/index\/.?)" ( ????? )

and rails doesn't delete any of the cache entries under "home/index"

Is there a mismatch between ".⁎" expected by ruby and "⁎" expected by redis ?
How can I take care of this issue ?

Does this pull request contain the solution ? ( #52 )


I am using, is it fixed in 1.1.0 ?

redis-store member

Regex, aren't supported because of the nature of Redis. We use KEYS ( to match what should be expired, but it just supports strings.


So what is the conclusion here? Since you are using keys, can a wildcard be passed into an expire_fragment? If so, what should it look like?

redis-store member

Let's say you have a partial in the download page with the most popular items, you may want to use expire_fragment(%r{popular.*}). As rule of thumb, check the documentation of KEYS that I linked above.


Sorry, how is this expected to work? It looks like you just pass whatever is passed to expire_fragment to DEL, which does not support wildcards. Is the behavior different on the version that works with Rails 3.0.10 from 3.1+ ?


Hello Guys,

Just a heads up: Regex's were not supported was quickly evident from the code. However, I found that even wildcard key matches were not working. Example:

def expire_cache
  a =
  a.expire_fragment 'logged_in/popular/*'
  a.expire_fragment 'logged_in/recent/*'
  a.expire_fragment 'logged_out/recent'
  a.expire_fragment 'logged_out/popular'

Please see this issue here #134 on why this was not working. I've submitted a pull request #167 to fix this, which is awaiting moderation and merge.

I've been using my own fork of this gem so far for this functionality, and I've tested it to be working (as per the above example). Hope it will help others.


@jodosha jodosha closed this Aug 29, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment