【问题标题】:Django Caching and condition decoratorDjango 缓存和条件装饰器
【发布时间】:2011-08-14 19:10:12
【问题描述】:

这是来自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.

所以我想知道当我同时使用站点缓存和条件装饰器时,Last-Modified 需要什么值。
编辑:另外,您会建议同时使用它们,还是只使用其中之一?

【问题讨论】:

    标签: django caching last-modified


    【解决方案1】:

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

    并且由于装饰器将在视图返回响应后直接执行,因此在中间件运行时装饰器标头已经存在。

    简而言之:Last-Modified 将具有来自 condition/last_modified 装饰器的值。

    【讨论】:

    • 我接受了您的回答,但是,您认为哪一个是最佳做法?两者都使用,还是让缓存句柄上次修改?
    猜你喜欢
    • 2015-07-29
    • 2017-03-21
    • 1970-01-01
    • 2015-11-18
    • 1970-01-01
    • 2019-02-19
    • 1970-01-01
    • 1970-01-01
    • 2017-08-21
    相关资源
    最近更新 更多