2011-10-27 15 views
2

here at the Django groups Tom Evans explains the method比较和设置在Django如下图所示Django的内存缓存:比较和设置

You can access the memcached client via django though: 
>>> from django.core import cache 
>>> c=cache.get_cache('default') 
>>> help(c._client.cas) 

但不知何故,我无法得到它的工作。

>>> from django.core import cache 
>>> c=cache.get_cache('memcache') 
>>> help(c._client.cas) 
Traceback (most recent call last): 
    File "<console>", line 1, in <module> 
AttributeError: 'MemcachedCache' object has no attribute '_client' 

我怎样才能做一个比较和Django中设置,如果上面显示不是方法?

我使用Django版本1.3。

回答

3

看完源代码!我觉得这是在BaseMemcachedCache:

@property 
def _cache(self): 
    """ 
    Implements transparent thread-safe access to a memcached client. 
    """ 
    if getattr(self, '_client', None) is None: 
     self._client = self._lib.Client(self._servers) 

    return self._client 

所以,我要说的是,这将工作:

c._cache.cas 

尝试,让我知道!

了解更多详情:https://code.djangoproject.com/svn/django/trunk/django/core/cache/backends/memcached.py