Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I clear rails cache after deploy to heroku?

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.

like image 999
kikiki.blue Avatar asked Aug 19 '12 16:08

kikiki.blue


People also ask

How do I clear the build cache Heroku?

Anyways, you can clear the build cache of an app easily by installing heroku-builds plugin. Note: The cache will be rebuilt on the next deployment. If you do not have any new code to deploy, you can push an empty commit.

How do I flush Rails cache?

clear in the Rails console to clear the cache. Unfortunately there is no way (yet) to do it from the command line. We can add a rake task that will do this for us. Then we can execute ./bin/rake cache:clear and clear the Rails cache from the command line.

Does heroku cache?

Heroku doesn't provide HTTP caching by default. In order to take advantage of HTTP caching, you'll need to configure your application to set the appropriate HTTP cache control headers and use a content delivery network (CDN) or other external caching service.

Where does Rails store cache?

This cache store uses Danga's memcached server to provide a centralized cache for your application. Rails uses the bundled dalli gem by default. This is currently the most popular cache store for production websites. It can be used to provide a single, shared cache cluster with very high performance and redundancy.


2 Answers

Rails has a built in rake task:

rake tmp:clear 
like image 139
gabeodess Avatar answered Sep 21 '22 03:09

gabeodess


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.

like image 43
a.ross.cohen Avatar answered Sep 20 '22 03:09

a.ross.cohen