Django缓存和条件装饰器

时间:2011-08-14 19:10:12

标签: django caching last-modified

这来自django documentation

condition(etag_func=None, last_modified_func=None)
etag(etag_func)
last_modified(last_modified_func)

These decorators can be used to generate ETag and Last-Modified headers

然而,这也来自django documentation

Additionally, the cache middleware automatically sets a few headers in each HttpResponse:
Sets the Last-Modified header to the current date/time when a fresh (uncached) version of the page is requested.
Sets the Expires header to the current date/time plus the defined CACHE_MIDDLEWARE_SECONDS.
Sets the Cache-Control header to give a max age for the page -- again, from the CACHE_MIDDLEWARE_SECONDS setting.

所以当我使用sitewise缓存和条件装饰器时,我想知道Last-Modified的值是多少 编辑:而且,你会建议同时使用它们,还是只使用其中一个?

1 个答案:

答案 0 :(得分:1)

缓存中间件只会设置ETagLast-ModifiedExpires标头(如果它们尚不存在)(请参阅{{3}调用的patch_response_headers方法}})。

由于装饰器将在从视图返回响应后直接执行,因此装饰器头将在中间件运行时出现。

简而言之:Last-Modified将具有条件/ last_modified装饰器的值。