INNER CODE UNIT · Python
get_latest_version_from_cache_file
stanfrbd/cyberbro · app.py:143
def get_latest_version_from_cache_file(cache_file: Path) -> str:
"""Check if the cache file exists and is not older than a day.
Return True if the cache file is valid and recent, False otherwise.
"""
if not cache_file.exists():
raise InvalidCachefileError("Cache file does not exist.")
try:
with cache_file.open() as f:
try:
cache_data = json.load(f)
except json.JSONDecodeError as e:
print("Cache file is corrupted, fetching latest version.")
logger.warning("Cache file is corrupted, fetching latest version.")
raise InvalidCachefileError("Cache file is corrupted.") from e