How can I clear rails cache after deploy to heroku?

Viewed 46715

I applied cache to my heroku rails app and it works well. But everytime I deploy to heroku, I also want to clear cache automatically.

so I googled and I found this.

task :after_deploy, :env, :branch do |t, args|
  puts "Deployment Complete"
  puts "Cleaning all cache...."
  FileUtils.cd Rails.root do
    sh %{heroku run console}
    sh %{Rails.cache.clear}
  end
end

but when I raked this script, it just show the heroku console command line but the Rails.cache.clear command does not typed. (I guess that is because heroku console is interactive)

and

system "heroku console Rails.cache.clear"

doesn't work for cedar apps.

How can I solve this problem?

Thanks.

8 Answers

Heroku has a release phase, which means you can put any deploy-time tasks inside your Procfile:

release: bundle exec rake tmp:clear

You might want to set up your own custom rake task to encapsulate any other tasks that need to happen at deploy, e.g.: db:migrate and so forth. Keep in mind that if the task fails for any reason, Heroku will halt the deploy and the previously deployed version of the code will remain active.

Related