What is the best way to automatically clear Memcached when I deploy my rails app to Heroku?
I'm caching the home page, and when I make changes and redeploy, the page is served from the cache, and the updates aren't incorporated.
I want to have this be totally automated. I don't want to have to clear the cache in the heroku console each time I deploy.
Thanks!
Builds are cached by branch. If you want to manually clear the cache and trigger a new build you can do so by clicking on the Trigger build dropdown button and selecting the Clear cache and build option.
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.
A simple JSON hash stored in Memcache can be useful for maintaining configuration that is accessed frequently. For example, a website may want to track which features are currently turned on, or which AB tests are running. Often these configurations are conveniently stored together in a JSON hash.
I deploy my applications using a bash script that automates GitHub & Heroku push, database migration, application maintenance mode activation and cache clearing action.
In this script, the command to clear the cache is :
heroku run --app YOUR_APP_NAME rails runner -e production Rails.cache.clear
This works with Celadon Cedar with the Heroku Toolbelt package. I know this is not a Rake-based solution however it's quite efficient.
Note : be sure you set the environment
/ -e
option of the runner
command to production
as it will be executed on the development
one otherwise.
Edit : I have experienced issues with this command on Heroku since a few days (Rails 3.2.21). I did not have time to check the origin the issue but removing the -e production
did the trick, so if the command does not succeed, please run this one instead :
heroku run --app YOUR_APP_NAME rails runner Rails.cache.clear
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