added dedicated test file and moved timed_cache to tools

This commit is contained in:
Mystical
2025-03-15 13:19:59 +05:30
committed by Paul Robinson
parent bf699351e1
commit c86f3d0467
12 changed files with 201 additions and 67 deletions

View File

@ -0,0 +1,22 @@
import time
from .base_timed_cache import (
BaseTimedCache,
)
class LastSeenCache(BaseTimedCache):
"""Cache where expiry is updated on every access."""
def add(self, key: bytes) -> bool:
with self.lock:
is_new = key not in self.cache
self.cache[key] = int(time.time()) + self.ttl
return is_new
def has(self, key: bytes) -> bool:
with self.lock:
if key in self.cache:
self.cache[key] = int(time.time()) + self.ttl
return True
return False