Rails 3 Caching: Expire Action for Named Route

expiring action from a different controller

I've got the answer for that.

By default caches_action ignores parameters.

And for getting the right fragment to be expired I did the following

expire_action store_url(host: my_host, store: store_name, locale: locale])

rails3 caching: expire fragment with extension

It appears that the problem was with routing setting default parameters. In the API controller, params[:format] was 'json' and in the Admin controller it was nil.

When I added this to my Admin controller:

params[:format] = 'json'
expire_action(:controller => 'api/books', :action => 'show', :id => @book.id, :format => 'json')

Then, the fragments in both controllers matched.

This let me back to my routes:

In my routes I had this:

namespace :api, :defaults => {:format => 'json'} do
resources :books, :only => [:show]
end

This caused params[:format] to be set in my api namespace. I didn't have anything in my admin namespace and apparently actionpack/ActionCachePath saw these two differently. Removing the defaults in the routes fixed the problem.

How do you expire an action for all formats in Rails? (expire_action)

I don't know of a better way than to explicitly expire each format unfortunately.

expire_action :action => :index
expire_action :action => :index, :format => 'json'

Rails caching: Expiring multiple pages for one action

I'm still interested in an answer to my original question and will change my accepted answer should a solution come up. That said, I ended up only caching the original page by checking if a page was specified at all:

caches_action :index, :if => Proc.new { params[:page].nil? }



Related Topics



Leave a reply



Submit