ba2429612a
- Doppelte Arcane-Einträge behoben (rippy statt Rippy) - Import-Fixes: relative → absolute imports in main.py, cache/__init__.py, prescan/__init__.py, clients/__init__.py - Neue Dateien: cache.py, prescan.py, Settings.tsx - API-Port 8000 in docker-compose.yml gemappt - UI mit Sidebar, Dark Mode, Einstellungen-Tabs Fixes: #2978 (doppelte Einträge), #2888 (Import-Fehler)
43 lines
961 B
Python
43 lines
961 B
Python
"""Cache module."""
|
|
|
|
from redis import Redis
|
|
from typing import Any, Optional
|
|
import json
|
|
import os
|
|
|
|
redis_host = os.getenv("REDIS_HOST", "redis")
|
|
redis_port = int(os.getenv("REDIS_PORT", "6379"))
|
|
|
|
redis_client = Redis(host=redis_host, port=redis_port, decode_responses=True)
|
|
|
|
|
|
def init_cache() -> None:
|
|
"""Initialize cache connection."""
|
|
pass
|
|
|
|
|
|
def get(key: str) -> Optional[Any]:
|
|
"""Get value from cache."""
|
|
value = redis_client.get(key)
|
|
if value:
|
|
return json.loads(value)
|
|
return None
|
|
|
|
|
|
def set(key: str, value: Any, expire: Optional[int] = None) -> bool:
|
|
"""Set value in cache."""
|
|
serialized = json.dumps(value)
|
|
if expire:
|
|
return redis_client.setex(key, expire, serialized)
|
|
return redis_client.set(key, serialized)
|
|
|
|
|
|
def delete(key: str) -> bool:
|
|
"""Delete value from cache."""
|
|
return redis_client.delete(key)
|
|
|
|
|
|
def clear() -> bool:
|
|
"""Clear all cache."""
|
|
return redis_client.flushdb()
|