djangorestframework不反映资源的变化

时间:2014-02-12 14:01:23

标签: django-rest-framework

当我使用json格式的curl对基于django-rest-framework的web服务进行一些发布/补丁请求时,我可以看到管理页面和数据库中的更改,但需要一些时间才能获得该数字反映在API(GET请求)

提前谢谢你。

1 个答案:

答案 0 :(得分:0)

还要确保您的中间件是 MIDDLEWARE_CLASSES 中的最后一件事。 根据django源代码中的文档:

django.middleware.cache.py (django 1.5版)

class UpdateCacheMiddleware(object):
    """
    Response-phase cache middleware that updates the cache if the response is
    cacheable.

    Must be used as part of the two-part update/fetch cache middleware.
    UpdateCacheMiddleware must be the first piece of middleware in
    MIDDLEWARE_CLASSES so that it'll get called last during the response phase.
    """
    # -- snip --

class FetchFromCacheMiddleware(object):
    """
    Request-phase cache middleware that fetches a page from the cache.

    Must be used as part of the two-part update/fetch cache middleware.
    FetchFromCacheMiddleware must be the last piece of middleware in
    MIDDLEWARE_CLASSES so that it'll get called last during the request phase.
    """
    # -- snip --

class CacheMiddleware(UpdateCacheMiddleware, FetchFromCacheMiddleware):
    """
    Cache middleware that provides basic behavior for many simple sites.

    Also used as the hook point for the cache decorator, which is generated
    using the decorator-from-middleware utility.
    """
    # -- snip --

希望有所帮助