diff --git a/django/core/cache/backends/locmem.py b/django/core/cache/backends/locmem.py
a
|
b
|
|
15 | 15 | _expire_info = {} |
16 | 16 | _locks = {} |
17 | 17 | |
| 18 | # Special timeout value used by incr and decr to instruct the cache to |
| 19 | # not change the existing timeout value |
| 20 | IGNORE_TIMEOUT = 'ignore' |
| 21 | |
18 | 22 | class LocMemCache(BaseCache): |
19 | 23 | def __init__(self, name, params): |
20 | 24 | BaseCache.__init__(self, params) |
… |
… |
|
71 | 75 | if timeout is None: |
72 | 76 | timeout = self.default_timeout |
73 | 77 | self._cache[key] = value |
74 | | self._expire_info[key] = time.time() + timeout |
| 78 | if timeout != IGNORE_TIMEOUT: |
| 79 | self._expire_info[key] = time.time() + timeout |
75 | 80 | |
76 | 81 | def set(self, key, value, timeout=None, version=None): |
77 | 82 | key = self.make_key(key, version=version) |
… |
… |
|
84 | 89 | finally: |
85 | 90 | self._lock.writer_leaves() |
86 | 91 | |
| 92 | def incr(self, key, delta=1, version=None): |
| 93 | """ |
| 94 | Add delta to value in the cache. If the key does not exist, raise a |
| 95 | ValueError exception. |
| 96 | """ |
| 97 | value = self.get(key, version=version) |
| 98 | if value is None: |
| 99 | raise ValueError("Key '%s' not found" % key) |
| 100 | new_value = value + delta |
| 101 | self.set(key, new_value, version=version, timeout=IGNORE_TIMEOUT) |
| 102 | return new_value |
| 103 | |
87 | 104 | def has_key(self, key, version=None): |
88 | 105 | key = self.make_key(key, version=version) |
89 | 106 | self.validate_key(key) |
diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py
a
|
b
|
|
822 | 822 | self.assertEqual(mirror_cache.get('value1'), 42) |
823 | 823 | self.assertEqual(other_cache.get('value1'), None) |
824 | 824 | |
| 825 | def test_incr_expiration(self): |
| 826 | self.cache.set('val', 42, timeout=2) |
| 827 | full_key = self.cache.make_key('val') |
| 828 | exp = self.cache._expire_info[full_key] |
| 829 | self.cache.incr('val') |
| 830 | exp2 = self.cache._expire_info[full_key] |
| 831 | self.assertEqual(exp, exp2) |
| 832 | |
825 | 833 | |
826 | 834 | # memcached backend isn't guaranteed to be available. |
827 | 835 | # To check the memcached backend, the test settings file will |