xiaozhi-esp32-server/main/xiaozhi-server/core/utils/cache/strategies.py
lapy c5ff101e66 feat(xiaozhi-server): western provider set, English defaults, runtime, and plugins
- Defaults and config aligned with English-first product surface

- Adds/removes ASR/TTS paths; drops China-only provider implementations and bundled SenseVoice assets

- Westernizes prompts, plugin/tool copy, connection and handler behavior on upstream fixes

- Powermem max_tokens and OpenAI no-thinking guard preserved on downstream path
2026-04-25 17:05:08 +01:00

43 lines
1 KiB
Python

"""
Cache strategies and data structure definitions
"""
import time
from enum import Enum
from typing import Any, Optional
from dataclasses import dataclass
class CacheStrategy(Enum):
"""Cache strategy enumeration"""
TTL = "ttl" # Time-based expiration
LRU = "lru" # Least recently used
FIXED_SIZE = "fixed_size" # Fixed size
TTL_LRU = "ttl_lru" # TTL + LRU hybrid strategy
@dataclass
class CacheEntry:
"""Cache entry data structure"""
value: Any
timestamp: float
ttl: Optional[float] = None # Time to live (seconds)
access_count: int = 0
last_access: float = None
def __post_init__(self):
if self.last_access is None:
self.last_access = self.timestamp
def is_expired(self) -> bool:
"""Check if expired"""
if self.ttl is None:
return False
return time.time() - self.timestamp > self.ttl
def touch(self):
"""Update access time and count"""
self.last_access = time.time()
self.access_count += 1