Rails: clear cached page

Rails automatically enables caching on Production and disables it on Development.

1. To disable caching on Production, edit config/environments/production.rb and set:

config.action_controller.perform_caching = false

2. To perform Page Caching use the caches_page method, e.g.:

class ProductsController < ActionController

 

  caches_page :index

 

  def index

    @products = Products.all

  end

end

3. If you need to debug what’s going on use:

tail -f current/log/production.log 

4. These may also help

http://stackoverflow.com/questions/2847859/rails-cache-clearing

http://stackoverflow.com/questions/17245401/rails-caching-on-production

https://news.ycombinator.com/item?id=1185473

(which points to: http://brainspl.at/nginx.conf.txt)

5. Finally, if you’re using Passenger then you may need to tell it to restart. 

Check whether this works (i.e. your content refreshes after this):

touch tmp/restart.txt

If so, then update your deploy.rb file with:

namespace :deploy do

  task :restart do

    run “touch #{current_path}/tmp/restart.txt”

  end

end

Thanks to:

http://stackoverflow.com/questions/3948074/capistrano-nginx-passenger-restart-rails-app/3948197

http://guides.rubyonrails.org/caching_with_rails.html#page-caching&nbsp;

Leave a Reply

Your email address will not be published. Required fields are marked *