beefier缓存控制由django中的@never_cache decorator创建的http头。
django-beefycachecontrol的Python项目详细描述
Django BeefyCacheControl是一个Django中间件,它使用更强大的反缓存HTTP头攻击行为不端的上游缓存提交。
通常,当视图用@never_cache装饰时:
@never_cache def my_view(request): ...
生成的http头(除其他外)包括:
Cache-Control max-age=0
虽然这应该足以防止响应被缓存到上游,但在某些情况下,这还不够。进入Django BeefierCacheControl!
启用BeefyCacheControlMiddleware后,这些HTTP头变成:
Cache-Control max-age=0, no-cache, no-store
把它存起来你就会被网络警察逮捕!
安装
- easy_install django-beefycachecontrol或pip install django-beefycachecontrol
- 将beefycachecontrol添加到INSTALLED_APPS
- 在settings.py中将'beefycachecontrol.middleware.BeefyCacheControlMiddleware'添加到MIDDLEWARE_CLASSES
用法
Django BeefyCacheControl是一个中间件。一旦启用,就没什么可做的了。它只是修复了与缓存无关的http头。