[ACCEPTED]-How can I clear rails cache after deploy to heroku?-deployment
Rails has a built in rake task:
rake tmp:clear
0
The following should work on cedar:
heroku run console
..then 13 wait 5 seconds for heroku console to boot
Rails.cache.clear
Then 12 you should see the cache clear, and you 11 can quit console. Remember you might have 10 to refresh a few times because your local 9 machine will often cache assets and such 8 in your browser until it makes a fresh request.
If 7 it happens to be assets that you're caching 6 though, you don't need to go through a manual 5 clear every time you push, you just need 4 to have the asset pipeline set up and make 3 sure all your js/css(less/sass)/static images 2 are being compiled with hashes at the end 1 of their filenames.
You should be able to create a cache clearing 4 rake task that looks something like this:
namespace :cache do
desc "Clears Rails cache"
task :clear => :environment do
Rails.cache.clear
end
end
and 3 invoke it directly in one command that you 2 can use in your post deploy hook - like 1 so:
heroku run rake cache:clear
Ruby on Rails has a magical ENV variable 2 called 'RAILS_CACHE_ID'. I set this to 1 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 9 deploy, I would recommend checking out:
https://github.com/gunpowderlabs/buildpack-ruby-rake-deploy-tasks
We've 8 been using it in production for over 6 months 7 and it's been rock solid.
First, add the 6 buildpack AFTER you already have the Ruby 5 buildpack set. This should happen after 4 your first deploy to the server
heroku buildpacks:add https://github.com/gunpowderlabs/buildpack-ruby-rake-deploy-tasks
Second, set 3 an environment variable called DEPLOY_TASKS
with just 2 the names of the rake tasks you want to 1 run separated by spaces.
heroku config:set DEPLOY_TASKS='cache:clear
Heroku doesn't currently support a pipeline 5 of actions to occur after deployment. You'll 4 need something like Codeship or TravisCI 3 to create a recipe of steps that happen 2 during deployment
Disclosure: I am a customer 1 of Codeship.
Heroku has a release
phase, which means you can put any deploy-time 7 tasks inside your Procfile
:
release: bundle exec rake tmp:clear
You might want to set 6 up your own custom rake task to encapsulate 5 any other tasks that need to happen at deploy, e.g.: db:migrate
and 4 so forth. Keep in mind that if the task 3 fails for any reason, Heroku will halt the 2 deploy and the previously deployed version 1 of the code will remain active.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.