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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With