trouble expiring fragment via regex #97

Closed
letronje opened this Issue Oct 20, 2011 · 6 comments

5 participants

@letronje

here's how my cache_action is defined :

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

in my sweeper,

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

def after_update
expire_fragment("home/index")
expire_fragment(/.home\/index\/.?/)
end

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 )

@letronje

I am using 1.0.0.1, is it fixed in 1.1.0 ?

@jodosha
redis-store member

Regex, aren't supported because of the nature of Redis. We use KEYS (http://redis.io/commands/keys) to match what should be expired, but it just supports strings.

@omricohen

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?

@jodosha
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.

@flippyhead

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+ ?

@jasdeepsingh

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 = ActionController::Base.new
  a.expire_fragment 'logged_in/popular/*'
  a.expire_fragment 'logged_in/recent/*'
  a.expire_fragment 'logged_out/recent'
  a.expire_fragment 'logged_out/popular'
end

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.

Thanks!

@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