高見龍
高見龍

Reputation: 839

caches_page seems doesn't work properly in Rails 3?

I used caches_page in rails 3, everything went well, but I don't want those cache files spread in public directory by default, so I changed the default cache directory like this:

config.action_controller.page_cache_directory = Rails.public_path + "/caches"

Yes, it still works, it writes cache file to public/caches directory, but it seems doesn't read it back while refreshing the same page, it writes a new cache file again every time.

Is there something or any configuration I should do to fix this? or I should just use the default cache directory?

thank you all :)

eddie

Upvotes: 2

Views: 1339

Answers (2)

Ahmed Samir Shahin
Ahmed Samir Shahin

Reputation: 558

Actually it is related to the server that is running the application .

for example: Webrick default cache directory is "public"

So when you set page_cache_directory to public, cached pages will be served properly .

The issue is related to the server not the app at all .

Quoted from http://guides.rubyonrails.org/caching_with_rails.html :

"By default, the page cache directory is set to Rails.public_path (which is usually set to the public folder) and this can be configured by changing the configuration setting config.action_controller.page_cache_directory. Changing the default from public helps avoid naming conflicts, since you may want to put other static html in public, but changing this will require web server reconfiguration to let the web server know where to serve the cached files from."

Upvotes: 1

deb
deb

Reputation: 12824

You might need to add a / after caches, try:

config.action_controller.page_cache_directory = Rails.public_path + "/caches/"

I have this on a Rails 3 app and it works:

config.action_controller.page_cache_directory = Rails.root.to_s + "/tmp/cache/"

Upvotes: 0

Related Questions