MCPcopy
hub / github.com/caronc/apprise / __load_cache

Method __load_cache

apprise/persistent_store.py:930–1013  ·  view source on GitHub ↗

Loads our cache. _recovery is reserved for internal usage and should not be changed

(self, _recovery=False)

Source from the content-addressed store, hash-verified

928 return change
929
930 def __load_cache(self, _recovery=False):
931 """Loads our cache.
932
933 _recovery is reserved for internal usage and should not be changed
934 """
935
936 # Prepare our dirty flag
937 self.__dirty = False
938
939 if self.__mode == PersistentStoreMode.MEMORY:
940 # Nothing further to do
941 self._cache = {}
942 return True
943
944 # Prepare our cache file
945 cache_file = self.cache_file
946 try:
947 with gzip.open(cache_file, "rb") as f:
948 # Read our ontent from disk
949 self._cache = {}
950 for k, v in json.loads(f.read().decode(self.encoding)).items():
951 co = CacheObject.instantiate(v)
952 if co:
953 # Verify our object before assigning it
954 self._cache[k] = co
955
956 elif not self.__dirty:
957 # Track changes from our loadset
958 self.__dirty = True
959
960 except (
961 UnicodeDecodeError,
962 json.decoder.JSONDecodeError,
963 zlib.error,
964 TypeError,
965 AttributeError,
966 EOFError,
967 ):
968 # Let users known there was a problem
969 logger.warning(
970 "Corrupted access persistent cache content: %s", cache_file
971 )
972
973 if not _recovery:
974 try:
975 os.unlink(cache_file)
976 logger.trace(
977 "Removed previous persistent cache content: %s",
978 cache_file,
979 )
980
981 except FileNotFoundError:
982 # no worries; we were removing it anyway
983 pass
984
985 except OSError as e:
986 # Permission error of some kind or disk problem...
987 # There is nothing we can do at this point

Callers 9

getMethod · 0.95
setMethod · 0.95
clearMethod · 0.95
pruneMethod · 0.95
__delitem__Method · 0.95
__contains__Method · 0.95
__setitem__Method · 0.95
__getitem__Method · 0.95
keysMethod · 0.95

Calls 3

openMethod · 0.45
readMethod · 0.45
instantiateMethod · 0.45

Tested by

no test coverage detected