Django缓存 - 删除特定页面的缓存 [英] Django Caching - Remove caching for certain pages
问题描述
当访问该视图时,我想对特定页面关闭缓存。这是一个简单地查询模型对象的页面。
I would like to turn caching off for certain pages when that view is accessed. It's for a page that simply queries model objects.
看起来像
'django.middleware.cache.FetchFromCacheMiddleware',
启用,它需要从浏览器另一个刷新来查看最新的数据。
it seems like when 'django.middleware.cache.FetchFromCacheMiddleware', is enabled, it requires another "refresh" from the browser to see the latest data.
有没有办法阻止这种情况?
Is there any way to prevent this?
谢谢。
推荐答案
https://docs.djangoproject.com/en/dev/topics/cache/#controlling-cache-using-other-headers
如果要使用标题来完全禁用缓存,
django.views.decorators.cache.never_cache是一个视图装饰器,
添加标题,以确保响应不会被浏览器缓存,或
其他缓存。示例:
If you want to use headers to disable caching altogether, django.views.decorators.cache.never_cache is a view decorator that adds headers to ensure the response won't be cached by browsers or other caches. Example:
from django.views.decorators.cache import never_cache
@never_cache
def myview(request):
# ...
这篇关于Django缓存 - 删除特定页面的缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!