While playing around with Rails page caching, we discovered a peculiar quirk. Any pages set to be cached are saved as static HTML files, but Mongrel doesn’t seem to be able to find them and continues to process subsequent requests dynamically. This only happens though if you change the Rails’ page cache directory in your application configuration. Upon digging further, here’s what we uncovered.
By default, Rails will cache files in /public, and this works fine if you enable caching in your development environment. However, with a different cache location, such as
config.action_controller.page_cache_directory = RAILS_ROOT + "/tmp/cache" |
things no longer work as expected. It turns out that Mongrel completely ignores this setting when looking for cached content. Furthermore, Mongrel’s directory handler assumes that files will always be located under /public.
If you want to patch this up on your local machine, just apply this Mongrel patch.
Here’s some useful info if you’re implementing page caching in Ruby on Rails.
after_filter { |c| c.cache_page} |
Leave a Reply (Textile enabled)