2011-10-27 16 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