Rails won't cache my action


#1

I’ve decided to dive into page caching for my rails app. I’m doing my
testing with webbrick and it refuses to display the cached page for a
particular action. I’ve modified my paginator helper to put the page
parameter in the url so that the paginated page can be used with
caching. This works perfectly when the page parameter is in the url (ie
browse/2006/2 or browse/2006/1). Both of those url put the cached file
in public/browse/2006/1.html and 2.html. They work fine and webbrick
displays the cached version. If I leave off the trailing 1 or 2 then
the cached file is created in public/browse/2006.html. The file is
getting created with each request instead of serving the cached version.
What can I do to fix this problem. I’m running rails 1.1 Here is my
routes.rb. I think it might have something to do with the problem.
map.connect ‘pragmatic/browse/:id/:page’,
:controller => ‘pragmatic’,
:action => ‘browse_date’,
:requirements => { :page => /\d+/},
:page => nil,
:id => /\d\d\d\d/


#2

Are you running in the development environment? Caching only works when
your environment is production.

~ Ben


#3

whoops… didn’t read all the way through… how are you setting up the
caching in your controller?


#4

Ben R. wrote:

whoops… didn’t read all the way through… how are you setting up the
caching in your controller?

Here is my controler caching line
caches_page :index, :view, :browse, :browse_date, :rss


#5

charlie bowman wrote:

Ben R. wrote:

whoops… didn’t read all the way through… how are you setting up the
caching in your controller?

Here is my controler caching line
caches_page :index, :view, :browse, :browse_date, :rss

It turns out the problem is in the routes.rb
I’m not sure why but I had to make the following change so that there
the action portion of the route wasn’t hard coded. Maybe someone knows
why this works but the previous example of mine didn’t.

map.connect ‘pragmatic/:action/:id/:page’,
:controller => ‘pragmatic’,
:requirements => { :page => /\d+/},
:page => nil,
:id => /\d\d\d\d/