Cache(maxsize, path, ttl)— persistent LRU cache with OrderedDict in memory.CacheConfigdataclass for ergonomic configuration.@persistent_lru_cachedecorator — drop-in alternative tofunctools.lru_cachewith disk persistence.- Atomic write via
os.replace+fsync(crash-safe on POSIX; best-effort on Windows). - Portable exclusive file locking:
fcntl.flockon POSIX,msvcrt.lockingon Windows. - Fork safety: PID is tracked; on first access after
fork()the on-disk state is re-read before any write, avoiding stale snapshots across processes. - Per-entry TTL support (absolute expiry timestamp).
- Zero dependencies — Python 3.9+ stdlib only.
- Thread-safe within a single process via
threading.RLock. - 8 unit tests covering get/set, LRU eviction, persistence across re-instantiation, TTL expiry, fork detection, atomic write semantics, stats, and clear.
- CI matrix: 3 OS × 4 Python versions (12 combos).