我配置了USE_ETAGS=True后依然无效,二次访问时直接就调用缓存了。
下面是我的中间件
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.views.decorators.http.ConditionalGetMiddleware',
]
下面是views.py
from django.http import HttpResponse
from django.views.decorators.http import condition
from app2.models import Book
def latest_entry(request,pk):
return Book.objects.filter(user_id=pk).latest("published").published
def img_etag(request,pk):
etaghead = hash(str(Book.objects.filter(user_id=pk).latest("published").bookname))
return str(etaghead)
@condition(etag_func=img_etag,last_modified_func=latest_entry)
def cc(request,pk):
data = Book.objects.filter(user_id=pk).latest("published").bookname
return HttpResponse(data)
取消全站缓存后,就condition才起作用。
我想知道全站缓存和condition冲突吗?
如果不冲突的话用该如何解决
多谢多谢了