django cache_page 如何设置版本
django cache_page how to set version
我可以通过cache.set
设置版本:
cache.set(key, value, timeout=60, version=1)
但是cache_page装饰器如何设置?
喜欢:
@cache_page(60, version=1)
def view(request):
django documentation 提到缓存装饰器只能接受一个参数和 2 个可选的 none 其中用于版本控制,恐怕您将不得不使用缓存函数进行版本控制或尝试向装饰器添加您自己的功能。
编辑:
设置版本的唯一方法是
incr_version('my_key')
和
decr_version('my_key')
您必须在 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
}
}
现在在你的装饰器中你会指定:
@cache_page(60, cache="my_cache")
def view(request):
我可以通过cache.set
设置版本:
cache.set(key, value, timeout=60, version=1)
但是cache_page装饰器如何设置?
喜欢:
@cache_page(60, version=1)
def view(request):
django documentation 提到缓存装饰器只能接受一个参数和 2 个可选的 none 其中用于版本控制,恐怕您将不得不使用缓存函数进行版本控制或尝试向装饰器添加您自己的功能。
编辑: 设置版本的唯一方法是
incr_version('my_key')
和
decr_version('my_key')
您必须在 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
}
}
现在在你的装饰器中你会指定:
@cache_page(60, cache="my_cache")
def view(request):