超过here at the Django groups Tom Evans explains the method在 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。
最佳答案
看完源码!我在 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
关于python - Django 内存缓存 : Compare and Set,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7917604/