0

Using Django and Memcached, I have a series of caches that I would like to invalidate. I've been saving them all to unique version numbers so I can invalidate them. However, following the directions from the Django site I get a ValueError.

My version numbers look something like: 20991791. So integers, in general.

How can I invalidate all memcache keys in version 20991791?

Just for reference, setting as follows:

>>> cache.set('laugh',2,version=3)

By only knowing version number "3" I need to be delete all keys in version number three. I thought incr_version did this, but when I try, it gives a valueerror.

>>> cache.incr_version(3)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/opt/virtual-envs/govini-web/lib/python2.6/site-packages/django/core/cache/backends/base.py", line 214, in incr_version
    raise ValueError("Key '%s' not found" % key)
ValueError: Key '3' not found
James R
  • 4,571
  • 3
  • 30
  • 45
  • you can delete a specific version with [`cache.delete('laugh', version=3)`](https://github.com/django/django/blob/master/django/core/cache/backends/memcached.py#L68). `cache.incr_version('laugh')` will just automatically bump the version, not invalidate any previous versions - afaik. Also, notice that it's a key and not a version number passed as the parameter – Timmy O'Mahony Aug 13 '12 at 23:37

1 Answers1

0

There is no good way to do this. There is a one of possible solution in memcached FAQ.

Also you can use cache backend with patterns support, django-redis for example, and delete with pattern "{KEY_PREFIX}:{VERSION}:*"

Community
  • 1
  • 1
Fedor Gogolev
  • 10,391
  • 4
  • 30
  • 36