每次部署网站时,如何让Google App Engine清除内存缓存? [英] How can I have Google App Engine clear memcache every time a site is deployed?
问题描述
更新1
使用 jldupont 的 answer 我将以下代码放在我的主请求处理脚本中...
更新2
我已经切换到 Koen Bok 在所选答案的评论中,并将所有我的memcache密钥与 os.environ ['CURRENT_VERSION_ID'] /
答案的第二次更新。这个解决方案似乎比我之前发布的功能更加优雅。
你尝试过 flush_all ()
函数? 此处的文档。你需要一点逻辑和状态检测新的部署或具有执行冲洗的特殊脚本。
更新:查看您的一个脚本的绝对路径:每个部署都会发生变化。您可以使用 http://shell.appspot.com/ 来实验:
import sys
sys.path
['/ base / python_dist / lib / python25.zip',
'/base/python_lib/versions/third_party/django-0.96',
' base / python_dist / lib / python2.5 /',
'/base/python_dist/lib/python2.5/plat-linux2',
'/base/python_dist/lib/python2.5/lib -tk',
'/base/python_dist/lib/python2.5/lib-dynload',
'/ base / python_lib / versions / 1',
'/ base / data / home / apps / shell / 1.335852500710379686 /']
查看与 /shell/1.335852500710379686 /
所以,只需保留这个部署状态变量的快照(在memcache ;-)中,并进行比较,以便进行刷新操作。
已更新2 :由@Koen Bok建议,环境变量 CURRENT也可以使用_VERSION_ID (脚本文件的绝对路径的一部分)。
import os
os.environ [CURRENT_VERSION_ID]
The title asks it all. The content on the site I'm building wont change very quickly at all and so Memcache could potentially store data for months except for when I put up an update. Is there a way to make it clear the cache every time I deploy the site? I'm using the Python runtime.
Update 1
Using jldupont's answer I put the following code in my main request handling script...
Update 2
I've switched to the method mentioned by Koen Bok in the selected answer's comments and prefixed all my memcache keys with os.environ['CURRENT_VERSION_ID']/
with the helpful code in the answer's 2nd update. This solution seems to be much more elegant than the function I posted before.
Have you tried flush_all()
function? Docs here. You'll need a bit of logic & state to detect a new deployment or have a special script to perform the flushing.
Updated: look at the absolute path of one of your script: this changes on every deployment. You can use http://shell.appspot.com/ to experiment:
import sys
sys.path
['/base/python_dist/lib/python25.zip', '/base/python_lib/versions/third_party/django-0.96', '/base/python_dist/lib/python2.5/', '/base/python_dist/lib/python2.5/plat-linux2', '/base/python_dist/lib/python2.5/lib-tk', '/base/python_dist/lib/python2.5/lib-dynload', '/base/python_lib/versions/1', '/base/data/home/apps/shell/1.335852500710379686/']
Look at the line with /shell/1.335852500710379686/.
So, just keep a snapshot (in memcache ;-) of this deployment state variable and compare in order to effect a flushing action.
Updated 2: as suggested by @Koen Bok, the environment variable CURRENT_VERSION_ID can be used also (part of the absolute path to script files also).
import os
os.environ["CURRENT_VERSION_ID"]
这篇关于每次部署网站时,如何让Google App Engine清除内存缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!