Spaces:
Build error
Build error
Download app/services/cache.py from ariansyahdedy/chat: direct link, hf CLI and curl.
- Browser
- Download file 689 Bytes
-
https://huggingface.co/spaces/ariansyahdedy/chat/resolve/main/app/services/cache.py
- Command line
-
hf download hf://spaces/ariansyahdedy/chat/app/services/cache.py
-
curl -L -o cache.py https://huggingface.co/spaces/ariansyahdedy/chat/resolve/main/app/services/cache.py
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 | |
| } | |