django-newcache icon indicating copy to clipboard operation
django-newcache copied to clipboard

incr() and decr() fail

Open joshourisman opened this issue 14 years ago • 1 comments

I'm using django-newcache on top of memcached with python-memcache on Django 1.3. For some reason incr() and decr() always fail with a ValueError saying the key cannot be found, even though get() can find it just fine. Here's a copy and paste from the shell:

>>> cache.set('test', 0)
True
>>> cache.get('test')
0
>>> cache.incr('test')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/josho/.virtualenvs/faceuptoit/lib/python2.7/site-packages/newcache.py", line 210, in incr
    raise ValueError("Key '%s' not found" % (key,))
ValueError: Key 'test' not found
>>> cache.decr('test')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/josho/.virtualenvs/faceuptoit/lib/python2.7/site-packages/newcache.py", line 216, in decr
    raise ValueError("Key '%s' not found" % (key,))
ValueError: Key 'test' not found
>>> cache.get('test')
0

joshourisman avatar Aug 25 '11 18:08 joshourisman

Ah, this is due to the thundering herd protection. You need to pass herd=False to the set() method and then it will work.

This should probably be clearer in the documentation, I didn't expect (though perhaps I should have?) to have to read through the note at the end of the thundering herd mitigation section in order to figure this out.

joshourisman avatar Aug 25 '11 19:08 joshourisman