Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 非常奇怪的行为:Django的cache.get方法返回不同的值_Python_Django_Caching_Memcached_Couchbase - Fatal编程技术网

Python 非常奇怪的行为:Django的cache.get方法返回不同的值

Python 非常奇怪的行为:Django的cache.get方法返回不同的值,python,django,caching,memcached,couchbase,Python,Django,Caching,Memcached,Couchbase,我正在使用django的缓存后端与遵循memcached协议的moxi客户端进行交互 我的测试代码是这样构造的 from django.core.cache import cache key = "test_object_key" max_errors = 15 errors = 0 total_runs = 0 unexpected_objects_returned = [] while(errors<max_errors): total_runs += 1 obj =

我正在使用django的缓存后端与遵循memcached协议的moxi客户端进行交互

我的测试代码是这样构造的

from django.core.cache import cache
key = "test_object_key"
max_errors = 15
errors = 0
total_runs = 0
unexpected_objects_returned = []
while(errors<max_errors):
    total_runs += 1
    obj = cache.get(key)
    if(type(obj)  == ExpectedObject):
        continue
    else:
        unexpected_objects_returned.append(obj)
        errors += 1
一切正常。正因为如此,我预计问题将出现在Django的某个地方,而不是moxi客户机或couchbase的下游

我会实现这个解决方案,但是我有一个巨大的Django项目,确保每个文件都包含它将是一件痛苦的事情。任何关于解决方案的提示都将不胜感激


我正在使用Django 1.3

它是否与django所做的内部键前缀有关?我在它和memcached上遇到了问题,所以我最终使用了cache.\u cache来访问memcached客户端本身。内部密钥缓存应该仍然意味着我得到了相同的对象,即使它是错误的对象。问题是缓存在循环通过我指定的同一个键时返回不同的对象。哦,我明白了,您得到的是不同的对象。
from django.core.cache import get_cache
cache = get_cache('default')