Rails fragment caching

software development

#1

I’ve been developing an app that uses fragment caching to a great degree. However, when I move the app to my dreamhost server, it doesn’t create any cache files. I have added this line to my environment.rb file:

ActionController::Base.fragment_cache_store = :file_store, “#{RAILS_ROOT}/cache”

I have double-checked that I am running in production mode, and that in my environments/production.rb file, I have:

config.action_controller.perform_caching = true

I’ve even enabled perform_caching in my development and test config files just in case it was reading them by some bizarre circumstance.

I have created the “cache” directory in the rails root, and even tried chmod’ing it to 777 to be sure there were no permission issues.

It shows no attempt to create the fragments, and gives no errors in the production.log. It simply behaves as if caching were disabled.

On my development machine, caching works perfectly.

Any advice/suggestions/solutions would be greatly appreciated.

Thanks.


#2

Heh, figured it out. Dispite what the rails docs say for fragment caching, the environment.rb file needs to use this line:

config.action_controller.fragment_cache_store = :file_store, “#{RAILS_ROOT}/cache”

instead of this one:

ActionController::Base.fragment_cache_store = :file_store, “#{RAILS_ROOT}/cache”

This wasn’t in the dreamhost config file, I had to dig it up from a commented line in an old rails app on my desktop.


#3

If you put your cache under /tmp/cache, you can take advantage of the rake tmp:cache:clear task. Just a helpful hint that I ran across.