每次部署站点时,如何使用Google App Engine清除内存缓存?
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.
标题要求一切。我正在建立的网站上的内容根本不会很快改变,所以Memcache可能会存储数月数据,除非我提出更新。有没有办法在每次部署站点时清除缓存?我正在使用Python运行时。
Update 1
Using jldupont's answer I put the following code in my main request handling script...
使用jldupont的答案我将以下代码放在我的主要请求处理脚本中......
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.
我已经在所选答案的注释中切换到Koen Bok提到的方法,并使用os.environ ['CURRENT_VERSION_ID'] /将所有我的memcache键作为答案的第二次更新中的有用代码。这个解决方案似乎比我之前发布的功能更优雅。
4 个解决方案
#1
21
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.
你试过flush_all()函数吗?文件在这里。您需要一些逻辑和状态来检测新部署或使用特殊脚本来执行刷新。
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:
更新:查看您的某个脚本的绝对路径:这会在每个部署中发生更改。您可以使用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/']
['/ 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 /版本/ 1','/ base / data / home / apps / shell / 1.335852500710379686 /']
Look at the line with /shell/1.335852500710379686/.
用/shell/1.335852500710379686/查看这一行。
So, just keep a snapshot (in memcache ;-) of this deployment state variable and compare in order to effect a flushing action.
因此,只需保留此部署状态变量的快照(在memcache ;-)中进行比较,以便实现刷新操作。
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).
更新2:正如@Koen Bok所建议的那样,环境变量CURRENT_VERSION_ID也可以使用(脚本文件的绝对路径的一部分)。
import os
os.environ["CURRENT_VERSION_ID"]
更多相关文章
- Python脚本如何获取当前环节和用户等信息
- python mysql 导出到mongodb脚本
- 脚本结束后如何运行进程并退出?
- 如何获得正在运行的Python脚本的路径?(复制)
- Shell脚本更改带变量的目录
- Linux(Debian)设置开机自启动脚本
- 《Linux命令行与shell脚本》笔记--第5章:使用Linux环境变量
- linux shell脚本编程笔记(四): 获取字符串长度的七种方法
- 查看Linux服务器网卡流量小脚本shell和Python各一例