python - Django 内存缓存 : Compare and Set

标签 python django caching memcached

超过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/

相关文章:

python - 如何比较具有相同列但不同行数的两个数据框?

python - 使用 django 模板向后循环

找不到 Django.conf 模块,为什么?

javascript - Redis - 持久化个人散列

python - 确定 8 位模 256 校验和形式 ascii 字符串 [-Python]

python - 迭代使用 "locals": Python 生成的多个数据帧

python - 在我的项目中,当我安装 django-filebrowser 时发生了一些冲突,仅样式冲突没有任何功能冲突

java - 删除 Java 的 "temporary internet files"

php - 如何在 PHP 中的请求之间持久化对象

python - 尝试在 python 中解码 HTTP 响应。无法弄清楚JSON解码