我正在尝试使用低级缓存API缓存request.POST
dict,但它似乎无法正常工作。我得到None
值而不是缓存的字典。
这是我试过的:
print cache.get('forms_data') # It is None
education_formset = Education(
request.POST or cache.get('forms_data') or None, prefix='education')
if education_formset.is_valid():
if 'view' in request.POST:
cache.set('forms_data', request.POST, 600)
设定:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': 'unix:/tmp/memcached.sock',
}
}
运行代码时没有异常。
设置或unix memcached.sock
可能有问题吗?
答案 0 :(得分:0)
DrTyrsa在评论中指出,cache.set
会返回无。
然而,我无法弄清楚你想要在这里实现的目标。缓存是全局的:对于您网站的所有用户来说都是一样的。你在这里做的是缓存一个用户的POST值,然后为所有其他用户检索它们。我非常怀疑这是你想要的。
如果您想存储用户的提交内容,请将其保留在会话中。