我需要向用户返回一个相当大的文件(11MB).出于某些原因,我不能只提供文件的直接URL(http://www.sample.com/mybigfile.exe); 相反,它必须通过代码访问.
我不想一遍又一遍地从磁盘上读取它,而是想把它保存在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)
Run Code Online (Sandbox Code Playgroud) 我正在使用 Ruby on Rails 和 dalli gem 来使用 memcache 进行缓存。
默认值(键值存储中的值,又名slab)最大大小为1MB。
我想将其增加到 2MB。
value_max_bytes: The maximum size of a value in memcached. Defaults to 1MB, this can be increased with memcached's -I parameter. You must also configure Dalli to allow the larger size here.
使用-I选项时memcached,如何指定 2MB?是 -I2 还是 -I2000?(文档对此不清楚)
对于达利宝石,我有,在 environments/development.rb
config.cache_store = :dalli_store
Run Code Online (Sandbox Code Playgroud)
我没有明确提到 Dalli::Client.new 那么我该如何设置value_max_bytes?
我查看了有关 stackoverflow 的相关问题,看来我需要安装 rack-cache gem。这是必要的吗?
谢谢你。