在 Heroku 部署上清除 Memcached [英] Clear Memcached on Heroku Deploy
问题描述
当我将 Rails 应用部署到 Heroku 时,自动清除 Memcached 的最佳方法是什么?
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.
我想让这完全自动化.我不想每次部署时都必须清除 heroku 控制台中的缓存.
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.
谢谢!
推荐答案
我使用自动化 GitHub 的 bash 脚本部署我的应用程序 &Heroku 推送、数据库迁移、应用维护模式激活和缓存清除动作.
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
这适用于带有 Heroku Toolbelt 包的 Celadon Cedar.我知道这不是基于 Rake 的解决方案,但它非常有效.
This works with Celadon Cedar with the Heroku Toolbelt package. I know this is not a Rake-based solution however it's quite efficient.
注意:确保将 runner
命令的 environment
/-e
选项设置为 production
作为否则将在 development
上执行.
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.
编辑:几天以来(Rails 3.2.21),我在 Heroku 上遇到了此命令的问题.我没有时间检查问题的根源,但删除 -e production
成功了,所以如果命令不成功,请改为运行这个:
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
这篇关于在 Heroku 部署上清除 Memcached的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!