Release f8bc9f00a67b9ec1dbc98cde15936107

This commit is contained in:
Dirk Alders 2024-12-04 08:26:03 +01:00
parent ed1082041f
commit ad5b0acc73

View File

@ -142,16 +142,24 @@ class property_cache_pickle(object):
:param default: value to be returned, if key does not exists.
:returns: value for a given key or default value.
"""
if key in self._source_instance.keys() and key not in self._source_get_keys:
# Init cache
if self._cached_props is None:
self._init_cache()
# Identify old cache
if self._max_age is None:
cache_old = False
else:
cache_old = time.time() - self._cached_props[self.AGE_TAG].get(self._key_filter(key), 0) > self._max_age
if cache_old:
logger.debug("The cached value is old, cached value will be ignored")
if self._key_filter(key) not in self._cached_props[self.DATA_TAG] or cache_old:
# Return cached value
if not cache_old and key not in self._source_get_keys and self._key_filter(key) in self._cached_props[self.DATA_TAG]:
logger.debug("Providing property for '%s' from cache", key)
rv = self._cached_props[self.DATA_TAG].get(self._key_filter(key), default)
if rv is not None or not self._return_source_on_none:
return rv
# Create cache and return value
if key in self._source_instance.keys():
logger.debug("Loading property for key='%s' from source instance", key)
val = self._source_instance.get(key, None)
if self._store_on_get:
@ -162,8 +170,6 @@ class property_cache_pickle(object):
self._save_cache()
else:
return val
else:
logger.debug("Providing property for '%s' from cache", key)
cached_data = self._cached_props[self.DATA_TAG].get(self._key_filter(key), default)
if cached_data is None and self._return_source_on_none:
return self._source_instance.get(key, default)