Skip to content

Commit

Permalink
Merge pull request #1243 from metno/1242-update-caching-strategy-for-…
Browse files Browse the repository at this point in the history
…ungridded-data

Cache validation ignore pyaerocom version; use mtime instead of ctime
  • Loading branch information
heikoklein authored Jul 5, 2024
2 parents 54dc319 + b1fa238 commit 7458cfc
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pyaerocom/io/cachehandler_ungridded.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,27 @@ def _check_pkl_head_vs_database(self, in_handle):
head = pickle.load(in_handle)
if not isinstance(head, dict):
raise CacheReadError("Invalid cache file")
pya_version = "pyaerocom_version"
for k, v in head.items():
if not k in current:
raise CacheReadError(f"Invalid cache header key: {k}")
elif not v == current[k]:
logger.info(f"{k} is outdated (value: {v}). Current value: {current[k]}")
return False
else:
if k == pya_version:
continue
elif v != current[k]:
logger.info(f"{k} is outdated (value: {v}). Current value: {current[k]}")
return False
if current[pya_version] != head[pya_version]:
logger.info(
f"cache generated with pyaerocom {head[pya_version]}, current is {current[pya_version]}"
)
return True

def cache_meta_info(self):
"""Dictionary containing relevant caching meta-info"""
try:
newestp = max(glob.iglob(os.path.join(self.src_data_dir, "*")), key=os.path.getctime)
newest_date = os.path.getctime(newestp)
newestp = max(glob.iglob(os.path.join(self.src_data_dir, "*")), key=os.path.getmtime)
newest_date = os.path.getmtime(newestp)
newest = os.path.basename(newestp)

except Exception:
Expand Down

0 comments on commit 7458cfc

Please sign in to comment.