diff --git a/django/core/cache/backends/locmem.py b/django/core/cache/backends/locmem.py
index cab690b..f68546e 100644
a
|
b
|
|
1 | 1 | "Thread-safe in-memory cache backend." |
2 | 2 | |
3 | 3 | import time |
| 4 | import threading |
4 | 5 | try: |
5 | 6 | from django.utils.six.moves import cPickle as pickle |
6 | 7 | except ImportError: |
… |
… |
from django.utils.synch import RWLock
|
12 | 13 | |
13 | 14 | # Global in-memory store of cache data. Keyed by name, to provide |
14 | 15 | # multiple named local memory caches. |
15 | | _caches = {} |
16 | | _expire_info = {} |
17 | | _locks = {} |
| 16 | _cache_info = {} |
| 17 | _cache_info_lock = threading.Lock() |
18 | 18 | |
19 | 19 | |
20 | 20 | class LocMemCache(BaseCache): |
21 | 21 | def __init__(self, name, params): |
22 | 22 | BaseCache.__init__(self, params) |
23 | | self._cache = _caches.setdefault(name, {}) |
24 | | self._expire_info = _expire_info.setdefault(name, {}) |
25 | | self._lock = _locks.setdefault(name, RWLock()) |
| 23 | if name in _cache_info: |
| 24 | cache_info = _cache_info[name] |
| 25 | else: |
| 26 | with _cache_info_lock: |
| 27 | cache_info = _cache_info.setdefault(name, ({}, {}, RWLock())) |
| 28 | self._cache, self._expire_info, self._lock = cache_info |
26 | 29 | |
27 | 30 | def add(self, key, value, timeout=DEFAULT_TIMEOUT, version=None): |
28 | 31 | key = self.make_key(key, version=version) |