added : timed_cache sub-module

This commit is contained in:
Mystical
2025-03-04 20:27:09 +05:30
committed by Paul Robinson
parent 0fa8711ca7
commit e5f3e88134
12 changed files with 158 additions and 20 deletions

View File

@ -0,0 +1,20 @@
import time
from .basic_time_cache import (
TimedCache,
)
class FirstSeenCache(TimedCache):
"""Cache where expiry is set only when first added."""
def add(self, key: bytes) -> bool:
with self.lock:
if key in self.cache:
return False
self.cache[key] = int(time.time()) + self.ttl
return True
def has(self, key: bytes) -> bool:
with self.lock:
return key in self.cache