Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
Borda committed Oct 25, 2024
1 parent d964093 commit ebc014c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/cachier/cores/pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(
self.separate_files = _update_with_defaults(
separate_files, "separate_files"
)
self._cache_loaded_fpath = ""
self._cache_used_fpath = ""

@property
def cache_fname(self) -> str:
Expand Down Expand Up @@ -115,7 +115,7 @@ def _load_cache_dict(self) -> Dict[str, CacheEntry]:
try:
with portalocker.Lock(self.cache_fpath, mode="rb") as cf:
cache = pickle.load(cf) # noqa: S301
self._cache_loaded_fpath = str(self.cache_fpath)
self._cache_used_fpath = str(self.cache_fpath)
except (FileNotFoundError, EOFError):
cache = {}
return {
Expand All @@ -124,7 +124,7 @@ def _load_cache_dict(self) -> Dict[str, CacheEntry]:
}

def get_cache_dict(self, reload: bool = False) -> Dict[str, CacheEntry]:
if self._cache_loaded_fpath != self.cache_fpath:
if self._cache_used_fpath != self.cache_fpath:
# force reload if the cache file has changed
# this change is dies to using different wrapped function
reload = True
Expand Down Expand Up @@ -181,6 +181,8 @@ def _save_cache(
with self.lock:
with portalocker.Lock(fpath, mode="wb") as cf:
pickle.dump(cache, cf, protocol=4)
if not separate_file_key:
self._cache_used_fpath = str(self.cache_fpath)
# the same as check for separate_file, but changed for typing
if isinstance(cache, dict):
self._cache_dict = cache
Expand Down

0 comments on commit ebc014c

Please sign in to comment.