在Django中战斗客户端缓存 [英] Fighting client-side caching in Django
本文介绍了在Django中战斗客户端缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用render_to_response快捷方式,不想制作特定的Response对象来添加额外的标头,以防止客户端缓存。
I'm using the render_to_response shortcut and don't want to craft a specific Response object to add additional headers to prevent client-side caching.
我会喜欢回应包含:
- pragma:no-cache
- 缓存控制:无缓存
- 缓存控制:必须重新生效
所有其他漂亮的方式那么浏览器将会希望解释为指令以避免缓存。
And all the other nifty ways that browsers will hopefully interpret as directives to avoid caching.
有没有缓存中间件或类似的东西,可以用最少的代码入侵来做这个伎俩?
Is there a no-cache middleware or something similar that can do the trick with minimal code intrusion?
推荐答案
您可以使用cache_control装饰器来实现。来自文档的示例:
You can achieve this using the cache_control decorator. Example from the documentation:
from django.views.decorators.cache import never_cache
@never_cache
def myview(request):
# ...
这篇关于在Django中战斗客户端缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文