我在浏览器中为应用程序引擎应用程序缓存图像时遇到一些问题
我正在发送上次修改、过期和缓存控制标头,但每次都会从服务器加载图像。
这是代码的标题部分:
响应['内容类型'] = '图像/jpg'
响应['上次修改'] = current_time.strftime('%a, %d %b %Y %H:%M:%S GMT')
响应['过期'] = current_time + timedelta(天=30)
响应['缓存控制'] = '公共,最大年龄=2592000'
这是我在 dpaste 中修复副本的示例代码here http://dpaste.com/hold/154503/
def view_image(request, key):
data = memcache.get(key)
if data is not None:
if(request.META.get('HTTP_IF_MODIFIED_SINCE') >= data['Last-Modified']):
data.status_code = 304
return data
else:
image_content_blob = #some code to get the image from the data store
current_time = datetime.utcnow()
response = HttpResponse()
last_modified = current_time - timedelta(days=1)
response['Content-Type'] = 'image/jpg'
response['Last-Modified'] = last_modified.strftime('%a, %d %b %Y %H:%M:%S GMT')
response['Expires'] = current_time + timedelta(days=30)
response['Cache-Control'] = 'public, max-age=315360000'
response['Date'] = current_time
response.content = image_content_blob
memcache.add(image_key, response, 86400)
return response
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)