Caching all the pages under a controller
I am working on a new Rails project these days and I was being asked to cache all the static pages displaying site’s static content. All the content was coming from one controller but I went crazy about implementing page caching by using caches_page, what I wanted to do was cache all the page in one go. Syntax for caching one or more pages is:
class WeblogController < ActionController::Basecaches_page :show, :newend
Now it is really a bad idea to go about writing all the content page names to ensure that they are cached. Even after looking for a solution to this on Internet I was unable to work out anything un-till I landed on a blog which was talking about a similar kind of problem. In responses to that post I finally found the solution:
after_filter lambda { |c| c.cache_page }, :except => [:show]
You are basically required to add a after filter to your controller of which you wish to cache all the pages, inside the except configuration you can specify the names of actions which you don’t want to be cached. So in short this works exactly the opposite of caches_page syntax.









Leave a Reply