File size: 2,255 Bytes
357bfdf 0743ddc 579285c 357bfdf 579285c 357bfdf 0743ddc 357bfdf 0743ddc 357bfdf 0743ddc 357bfdf 0743ddc 357bfdf 0743ddc 357bfdf 0743ddc 357bfdf 0743ddc 357bfdf 0743ddc 357bfdf 0743ddc 357bfdf 0743ddc 357bfdf 0743ddc 357bfdf 0743ddc 357bfdf 0743ddc 357bfdf 0743ddc 357bfdf 2a99443 0743ddc 2a99443 0743ddc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | """YAZ Care Platform - Cache Service Fallback"""
import time
from typing import Any, Dict, Optional
import structlog
logger = structlog.get_logger(__name__)
class SimpleCache:
"""Simple in-memory cache fallback"""
def __init__(self):
self._cache: dict[str, dict[str, Any]] = {}
self.hits = 0
self.misses = 0
def get(self, key: str) -> Any | None:
"""Get value from cache"""
try:
if key in self._cache:
entry = self._cache[key]
if entry.get("expires", 0) > time.time():
self.hits += 1
return entry["value"]
else:
# Expired, remove it
del self._cache[key]
self.misses += 1
return None
except Exception as e:
logger.warning(f"Cache get error: {e}")
return None
def set(self, key: str, value: Any, ttl: int = 300):
"""Set value in cache with TTL"""
try:
self._cache[key] = {
"value": value,
"expires": time.time() + ttl,
"created": time.time(),
}
except Exception as e:
logger.warning(f"Cache set error: {e}")
def delete(self, key: str):
"""Delete key from cache"""
self._cache.pop(key, None)
def get_stats(self) -> dict[str, Any]:
"""Get cache statistics"""
total = self.hits + self.misses
hit_ratio = (self.hits / total * 100) if total > 0 else 0
return {
"hits": self.hits,
"misses": self.misses,
"hit_ratio": hit_ratio,
"size": len(self._cache),
"status": "available",
}
# Global instance
cache = SimpleCache()
# Alias for backward compatibility (factory.py imports cache_manager)
cache_manager = cache
class HealthcareCacheNamespaces:
"""Cache namespace constants for healthcare modules"""
PATIENT = "patient"
CLINICAL = "clinical"
SURGICAL = "surgical"
LABORATORY = "laboratory"
PHARMACY = "pharmacy"
SCHEDULING = "scheduling"
BILLING = "billing"
INVENTORY = "inventory"
TENANT = "tenant"
CONFIG = "config"
|