bmc_hub/app/modules/manual/backend/cache.py
Christian ceb560e2f2 feat: Add bottom bar functionality with real-time updates and manual endpoint tests
- Implemented a new bottom bar feature in `bottom-bar.js` that fetches and displays various notifications and statuses in real-time.
- Added functions for handling visibility, state updates, and user interactions within the bottom bar.
- Introduced WebSocket connection for real-time updates and fallback polling mechanism.
- Created a manual testing script `test_manual.py` to validate API endpoints for the manual module.
- Included tests for various paths to ensure expected responses from the server.
2026-04-12 02:27:01 +02:00

33 lines
870 B
Python

import time
from typing import Any, Optional
class ManualCache:
"""
Very simple in-memory TTL cache for the Manual MVP.
Stores GET lists and details. Clears fully on any mutation.
"""
def __init__(self, ttl_seconds: int = 300):
self.ttl = ttl_seconds
self._store = {}
def get(self, key: str) -> Optional[Any]:
item = self._store.get(key)
if item is None:
return None
if time.time() > item["expires"]:
del self._store[key]
return None
return item["value"]
def set(self, key: str, value: Any):
self._store[key] = {
"value": value,
"expires": time.time() + self.ttl
}
def clear(self):
self._store.clear()
# Global singleton instance for the app
manual_cache = ManualCache(ttl_seconds=300) # 5 min cache