Rails ActionCaching with Memcached fragment hit but action gets called anyway
Posted
by baldtrol
on Stack Overflow
See other posts from Stack Overflow
or by baldtrol
Published on 2010-03-10T02:17:29Z
Indexed on
2010/04/09
21:03 UTC
Read the original article
Hit count: 245
ruby-on-rails
|memcached
Hi stackoverflow. I'm running into something strange. I'm using memcached with a caches_action setup. I'm doing this in 4 different controllers. In two of them, it works flawlessly (so far), though admittedly those two controllers are less complicated than the two in which it doesn't seem to work. I'm doing something like this:
caches_action :index, :expires_in => 6.hours, :cache_path => Proc.new {|controller| controller.send(:generate_cache_path) }, :layout => false, :if => Proc.new { |c| c.request.format.js? }
The intention behind the above is to cache some results that are dependent on the params. my :generate_cache_path method just takes into account some params and session vars and creates a unique key for memcached. I can see in memcached -vv that this is working.
What's weird is that I get my request from the rails app for a given key, and I see memcached (with -vv) get the request and send back the response. But then my action runs anyway, and a new value is then set for the same key, even when all the same params are given. I can watch it happen. In the controllers where everything is working, the request is made for the fragment, it gets it, and the action in the controller is halted, and the fragment is passed back.
These lines come from the exact same request:
Cached fragment hit: views/items/?page=1&rp=10&srtn=created_at&srto=DESC.js
And then:
Cached fragment miss: views/items/?page=1&rp=10&srtn=created_at&srto=DESC.js
I don't know what to make of it, or if I'm doing something stupid. Any help or ideas where I could start looking for trouble would be greatly appreciated.
© Stack Overflow or respective owner