chat / app /services /cache.py
ariansyahdedy's picture
Add Gemnini Flash
07fbc67
raw
history blame
689 Bytes
import time
from typing import Dict
class MessageCache:
def __init__(self, max_age_hours: int = 24):
self.messages: Dict[str, float] = {}
self.max_age_seconds = max_age_hours * 3600
def add(self, message_id: str) -> None:
self.cleanup()
self.messages[message_id] = time.time()
def exists(self, message_id: str) -> bool:
self.cleanup()
return message_id in self.messages
def cleanup(self) -> None:
current_time = time.time()
self.messages = {
msg_id: timestamp
for msg_id, timestamp in self.messages.items()
if current_time - timestamp < self.max_age_seconds
}