2012-04-29 74 views
0

我正在使用Django缓存来缓存某些页面。我使用@vary_on_cookie装饰器来允许登录用户缓存特定的用户详细信息。不过,我需要清除特定页面的特定用户的缓存。从基于cookie的Django缓存中删除特定值

即我需要一种方法来生成django中间件缓存生成密钥的相同密钥,使用cookie和路径等。然后我可以使用低级缓存来自行清除特定条目。

我该如何去做这件事?

回答

1

您正在寻找位于django.middleware.cache功能:

>>> from django.middleware.cache import get_cache_key as gk 
>>> help(gk) 

将返回以下:

get_cache_key(request, key_prefix=None, method='GET', cache=None) 
    Returns a cache key based on the request path and query. It can be used 
    in the request phase because it pulls the list of headers to take into 
    account from the global path registry and uses those to build a cache key 
    to check against. 

记住,你可以通过设置变量定义自己的键生成机制手动使用KEY_FUNCTION

HTH!

+0

谢谢我认为这就是我一直在寻找的。 – oracal 2012-04-29 13:37:49