Register cache instance after being fully initialized
Otherwise an instance can be accessed by another thread via the registry when it is still being initialized. And it may crash on missing attribute. Closes #15007 (grafted from f1840545f4eb5ae5c870a2557a7c3a0314fedb16) --HG-- branch : 8.0
This commit is contained in:
@@ -83,7 +83,15 @@ class _CacheLocal(local):
|
||||
self.portable_id = str(uuid4())
|
||||
|
||||
|
||||
class BaseCache(object):
|
||||
class _CacheMeta(type):
|
||||
def __call__(cls, *args, **kwargs):
|
||||
inst = super().__call__(*args, **kwargs)
|
||||
assert inst._name not in BaseCache._instances, inst._name
|
||||
BaseCache._instances[inst._name] = inst
|
||||
return inst
|
||||
|
||||
|
||||
class BaseCache(metaclass=_CacheMeta):
|
||||
_instances = {}
|
||||
context_ignored_keys = {
|
||||
'client', '_request', '_check_access', '_skip_warnings',
|
||||
@@ -112,8 +120,6 @@ class BaseCache(object):
|
||||
self.duration = dt.timedelta(**duration)
|
||||
else:
|
||||
self.duration = None
|
||||
assert self._name not in self._instances, self._name
|
||||
self._instances[self._name] = self
|
||||
|
||||
@classmethod
|
||||
def stats(cls):
|
||||
|
||||
Reference in New Issue
Block a user