diff --git a/django/core/cache/backends/locmem.py b/django/core/cache/backends/locmem.py
index 2734cef..2b807f0 100644
a
|
b
|
class CacheClass(BaseCache):
|
29 | 29 | |
30 | 30 | self._lock = RWLock() |
31 | 31 | |
32 | | def _add(self, key, value, timeout=None): |
33 | | if len(self._cache) >= self._max_entries: |
34 | | self._cull() |
35 | | if timeout is None: |
36 | | timeout = self.default_timeout |
37 | | if key not in self._cache.keys(): |
38 | | self._cache[key] = value |
39 | | self._expire_info[key] = time.time() + timeout |
40 | | |
41 | 32 | def add(self, key, value, timeout=None): |
42 | 33 | self._lock.writer_enters() |
43 | | # Python 2.3 and 2.4 don't allow combined try-except-finally blocks. |
44 | 34 | try: |
45 | | try: |
46 | | self._add(key, pickle.dumps(value), timeout) |
47 | | except pickle.PickleError: |
48 | | pass |
| 35 | now = time.time() |
| 36 | exp = self._expire_info.get(key) |
| 37 | if exp is None or exp < now: |
| 38 | try: |
| 39 | self._set(key, pickle.dumps(value), timeout) |
| 40 | except pickle.PickleError: |
| 41 | pass |
49 | 42 | finally: |
50 | 43 | self._lock.writer_leaves() |
51 | 44 | |
… |
… |
class CacheClass(BaseCache):
|
95 | 88 | self._lock.writer_leaves() |
96 | 89 | |
97 | 90 | def has_key(self, key): |
98 | | return key in self._cache |
| 91 | should_delete = False |
| 92 | self._lock.reader_enters() |
| 93 | try: |
| 94 | now = time.time() |
| 95 | exp = self._expire_info.get(key) |
| 96 | if exp is None: |
| 97 | return False |
| 98 | elif exp < now: |
| 99 | should_delete = True |
| 100 | else: |
| 101 | return True |
| 102 | finally: |
| 103 | self._lock.reader_leaves() |
| 104 | if should_delete: |
| 105 | self._lock.writer_enters() |
| 106 | try: |
| 107 | del self._cache[key] |
| 108 | del self._expire_info[key] |
| 109 | return False |
| 110 | finally: |
| 111 | self._lock.writer_leaves() |
99 | 112 | |
100 | 113 | def _cull(self): |
101 | 114 | if self._cull_frequency == 0: |