pydoh/tests/test_cache.py

30 lines
591 B
Python
Raw Permalink Normal View History

2026-07-19 20:36:56 +05:00
import time
2026-07-19 20:51:04 +05:00
from pydoh.cache import TTLCache
2026-07-19 20:36:56 +05:00
def test_cache_hit():
cache = TTLCache()
cache.set("k", ["1.2.3.4"], ttl=60)
assert cache.get("k") == ["1.2.3.4"]
def test_cache_expires():
cache = TTLCache()
cache.set("k", ["1.2.3.4"], ttl=0.05)
assert cache.get("k") == ["1.2.3.4"]
time.sleep(0.1)
assert cache.get("k") is None
def test_cache_clear():
cache = TTLCache()
cache.set("k", ["1.2.3.4"], ttl=60)
cache.clear()
assert cache.get("k") is None
def test_cache_miss():
cache = TTLCache()
assert cache.get("missing") is None