first commit

This commit is contained in:
Space-Banane
2026-05-29 19:15:00 +02:00
commit a54d1cfeaf
25 changed files with 1183 additions and 0 deletions

28
tests/test_cache.py Normal file
View File

@@ -0,0 +1,28 @@
import time
from app.cache import FileCache
def test_cache_returns_fresh_entry(tmp_path) -> None:
cache = FileCache(cache_dir=str(tmp_path), default_ttl_seconds=10)
cache.set_json("sample", {"x": 1})
entry = cache.get_json("sample")
assert entry is not None
assert entry.stale is False
assert entry.value == {"x": 1}
def test_cache_can_serve_stale_when_requested(tmp_path) -> None:
cache = FileCache(cache_dir=str(tmp_path), default_ttl_seconds=0)
cache.set_json("sample", {"x": 1})
time.sleep(0.01)
fresh = cache.get_json("sample")
stale = cache.get_json("sample", allow_stale=True)
assert fresh is None
assert stale is not None
assert stale.stale is True
assert stale.value == {"x": 1}