Quintin Par
Quintin Par

Reputation: 16252

Django Memcache : Compare and Set

Over here at the Django groups Tom Evans explains the method to do compare and set in Django as shown below

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

But somehow I couldn’t get it to work.

>>> 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'

How can I get to do a compare and set in Django, if not the method shown above?

I use Django version 1.3.

Upvotes: 2

Views: 1286

Answers (1)

Arthur Neves
Arthur Neves

Reputation: 12128

after looking at the source code! i find this at 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

So, I would say that, this will work:

c._cache.cas

Try, and let me know!

for more details: https://code.djangoproject.com/svn/django/trunk/django/core/cache/backends/memcached.py

Upvotes: 3

Related Questions