diff --git a/django/core/cache/backends/locmem.py b/django/core/cache/backends/locmem.py
index 9196b3b..0054d22 100644
a
|
b
|
class LocMemCache(BaseCache):
|
69 | 69 | def set(self, key, value, timeout=None, version=None): |
70 | 70 | key = self.make_key(key, version=version) |
71 | 71 | self.validate_key(key) |
| 72 | try: |
| 73 | pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL) |
| 74 | except pickle.PickleError: |
| 75 | return |
72 | 76 | with self._lock.writer(): |
73 | | try: |
74 | | pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL) |
75 | | self._set(key, pickled, timeout) |
76 | | except pickle.PickleError: |
77 | | pass |
| 77 | self._set(key, pickled, timeout) |
78 | 78 | |
79 | 79 | def incr(self, key, delta=1, version=None): |
80 | 80 | value = self.get(key, version=version) |
diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py
index 264ef74..07d0a66 100644
a
|
b
|
class C:
|
42 | 42 | return 24 |
43 | 43 | |
44 | 44 | |
| 45 | class PicklingSideEffect(object): |
| 46 | |
| 47 | def __init__(self, cache): |
| 48 | self.cache = cache |
| 49 | self.locked = False |
| 50 | |
| 51 | def __getstate__(self): |
| 52 | if self.cache._lock.active_writers: |
| 53 | self.locked = True |
| 54 | return {} |
| 55 | |
| 56 | |
45 | 57 | class DummyCacheTests(unittest.TestCase): |
46 | 58 | # The Dummy cache backend doesn't really behave like a test backend, |
47 | 59 | # so it has different test requirements. |
… |
… |
class LocMemCacheTests(unittest.TestCase, BaseCacheTests):
|
919 | 931 | self.assertEqual(mirror_cache.get('value1'), 42) |
920 | 932 | self.assertEqual(other_cache.get('value1'), None) |
921 | 933 | |
| 934 | def test_locking_on_pickle(self): |
| 935 | cache = self.cache |
| 936 | bad_obj = PicklingSideEffect(cache) |
| 937 | cache.set('bar', bad_obj) |
| 938 | assert bad_obj.locked == False, "Cache was locked during pickling" |
| 939 | |
922 | 940 | def test_incr_decr_timeout(self): |
923 | 941 | """incr/decr does not modify expiry time (matches memcached behavior)""" |
924 | 942 | key = 'value' |