views:

103

answers:

1

I have a controller Projects in my Rails app with:

caches_page :index

However, instead of the cached file being generated at /public/projects/index.html it is located at /public/projects.html.

The web server (currently Mongrel) looks for */ directories before *.html files. So the http://…/projects request is routed through Rails and my index cache file is never served.

How can I tell caches_page :index to generate the file at /public/projects/index.html instead?

A: 

You can specify the directory by adding the following to your environment.rb config block

config.cache_store = :file_store, "#{RAILS_ROOT}/public/projects" 

A couple other things:

  1. The cache settings have changed some with the different version of Rails, it would be helpful to know what version you are running

  2. In general you're probably better off using the cache memory store instead of file store (if you have sufficient RAM in your box).

Mike Buckbee
I’m using Rails 2.3.5. I might give memcaching a go, but RAM is likely to be tight, and I trust Apache to serve my small, low-traffic site efficiently. However, I’m not trying to change the cache root, just the caching behaviour of the index action.
Andy