from pathlib import Path
from datetime import datetime


def _valid_cache(path: Path, expired_days=30):
    """Return True if the file exists and is younger than `expired_days`."""
    if not path.is_file():
        return False
    days_old = (datetime.now() - datetime.fromtimestamp(path.stat().st_mtime)).days
    return days_old < expired_days