Ticket #16858: locmem-patch.diff

File locmem-patch.diff, 1004 bytes (added by boxm, 4 years ago)

Patch for locmem cache to bring incr() in line with memcached behaviour

  • webserver/lib/django-1.3/django/core/cache/backends/locmem.py

    diff --git a/webserver/lib/django-1.3/django/core/cache/backends/locmem.py b/webserver/lib/django-1.3/django/core/cache/backends/locmem.py
    index ecec875..7b1f845 100644
    a b class LocMemCache(BaseCache): 
    8686        finally:
    8787            self._lock.writer_leaves()
    8888
     89    def incr(self, key, delta=1, version=None):
     90        """
     91        Add delta to value in the cache.
     92        """
     93        value = self.get(key, version=version)
     94        if value is None:
     95            raise ValueError("Key '%s' not found" % key)
     96        full_key = self.make_key(key, version=version)
     97        exp = self._expire_info.get(full_key)
     98
     99        new_value = value + delta
     100        self.set(key, new_value, version=version, timeout=exp)
     101       
    89102    def has_key(self, key, version=None):
    90103        key = self.make_key(key, version=version)
    91104        self.validate_key(key)
Back to Top