简体   繁体   English

django cache_page 如何设置版本

[英]django cache_page how to set version

I can set version by cache.set :我可以通过cache.set设置版本:

cache.set(key, value, timeout=60, version=1)

but how to set by cache_page decorator?但是如何通过 cache_page 装饰器设置?

like:喜欢:

@cache_page(60, version=1)
def view(request):

The django documentation mentions that the cache decorator can only take a single argument and 2 optional none of which are for versioning, im afraid you will have to use the cache functions for versioning or attempt to add your own functionality to the decorators. django 文档提到缓存装饰器只能采用单个参数,而 2 个可选参数都不是用于版本控制,恐怕您将不得不使用缓存功能进行版本控制或尝试将自己的功能添加到装饰器中。

edit: the only way to set version is with编辑:设置版本的唯一方法是

incr_version('my_key') 

and

decr_version('my_key')

You have to add an entry to the CACHES (you would have to add the dictionary) dictionary in your settings.py:您必须在 settings.py 中向 CACHES(您必须添加字典)字典添加一个条目:

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
    },
    'my_cache': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
        'VERSION': 1 # Or of your preference
    }
}

Now in your decorator you would specify:现在在您的装饰器中,您将指定:

@cache_page(60, cache="my_cache")
def view(request):

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM