Fixes situation where attributes and tags continue to be cached when TYPECLASS_AGGRESSIVE_CACHE is set to False.

This commit is contained in:
Johnny 2019-12-03 21:35:51 +00:00
parent a6f5cccdfa
commit 270b50a984
3 changed files with 39 additions and 16 deletions

View file

@ -237,6 +237,7 @@ class AttributeHandler(object):
def _fullcache(self):
"""Cache all attributes of this object"""
if not _TYPECLASS_AGGRESSIVE_CACHE: return
query = {
"%s__id" % self._model: self._objid,
"attribute__db_model__iexact": self._model,
@ -298,7 +299,7 @@ class AttributeHandler(object):
attr = None
cachefound = False
del self._cache[cachekey]
if cachefound:
if cachefound and _TYPECLASS_AGGRESSIVE_CACHE:
if attr:
return [attr] # return cached entity
else:
@ -316,13 +317,15 @@ class AttributeHandler(object):
conn = getattr(self.obj, self._m2m_fieldname).through.objects.filter(**query)
if conn:
attr = conn[0].attribute
self._cache[cachekey] = attr
if _TYPECLASS_AGGRESSIVE_CACHE:
self._cache[cachekey] = attr
return [attr] if attr.pk else []
else:
# There is no such attribute. We will explicitly save that
# in our cache to avoid firing another query if we try to
# retrieve that (non-existent) attribute again.
self._cache[cachekey] = None
if _TYPECLASS_AGGRESSIVE_CACHE:
self._cache[cachekey] = None
return []
else:
# only category given (even if it's None) - we can't
@ -345,12 +348,13 @@ class AttributeHandler(object):
**query
)
]
for attr in attrs:
if attr.pk:
cachekey = "%s-%s" % (attr.db_key, category)
self._cache[cachekey] = attr
# mark category cache as up-to-date
self._catcache[catkey] = True
if _TYPECLASS_AGGRESSIVE_CACHE:
for attr in attrs:
if attr.pk:
cachekey = "%s-%s" % (attr.db_key, category)
self._cache[cachekey] = attr
# mark category cache as up-to-date
self._catcache[catkey] = True
return attrs
def _setcache(self, key, category, attr_obj):
@ -363,6 +367,7 @@ class AttributeHandler(object):
attr_obj (Attribute): The newly saved attribute
"""
if not _TYPECLASS_AGGRESSIVE_CACHE: return
if not key: # don't allow an empty key in cache
return
cachekey = "%s-%s" % (key, category)