我考虑将其保存在memcached中,以避免重复从磁盘中读取。一切似乎都很好(没有错误),但是当我尝试从memcached中检索文件时,我总是得到None,就好像文件没有缓存一样。
是否有大小限制可以被保存?
以下是代码:
def download_demo():
"""
Returns the demo file
"""
KEY = "xyz"
TIME = 86400 #24 hours
buff = memc.get(KEY)
if not buff:
file = open(FILENAME, 'r')
buff = file.read()
memc.set(KEY, buff, TIME)
print "Content-Type:application/x-download\nContent-Disposition:attachment;filename=%s\nContent-Length:%s\n\n%s" % (os.path.split(FILENAME)[-1], len(buff), buff)