How can I clear rails cache after deploy to heroku?

左心房为你撑大大i 提交于 2019-11-28 18:12:58

Rails has a built in rake task:

rake tmp:clear

The following should work on cedar:

heroku run console

..then wait 5 seconds for heroku console to boot

Rails.cache.clear

Then you should see the cache clear, and you can quit console. Remember you might have to refresh a few times because your local machine will often cache assets and such in your browser until it makes a fresh request.

If it happens to be assets that you're caching though, you don't need to go through a manual clear every time you push, you just need to have the asset pipeline set up and make sure all your js/css(less/sass)/static images are being compiled with hashes at the end of their filenames.

Ivar

You should be able to create a cache clearing rake task that looks something like this:

namespace :cache do
  desc "Clears Rails cache"
  task :clear => :environment do
    Rails.cache.clear
  end
end

and invoke it directly in one command that you can use in your post deploy hook - like so:

heroku run rake cache:clear

Ruby on Rails has a magical ENV variable called 'RAILS_CACHE_ID'. I set this to the git commit id whenever I deploy: heroku config:set RAILS_CACHE_ID=$CIRCLE_SHA1

If you want to simply run a rake task after deploy, I would recommend checking out:

https://github.com/gunpowderlabs/buildpack-ruby-rake-deploy-tasks

We've been using it in production for over 6 months and it's been rock solid.

First, add the buildpack AFTER you already have the Ruby buildpack set. This should happen after your first deploy to the server

heroku buildpacks:add https://github.com/gunpowderlabs/buildpack-ruby-rake-deploy-tasks

Second, set an environment variable called DEPLOY_TASKS with just the names of the rake tasks you want to run separated by spaces.

heroku config:set DEPLOY_TASKS='cache:clear

heroku run rake tmp:cache:clear

http://guides.rubyonrails.org/command_line.html#tmp

Heroku doesn't currently support a pipeline of actions to occur after deployment. You'll need something like Codeship or TravisCI to create a recipe of steps that happen during deployment

Disclosure: I am a customer of Codeship.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!