mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
- 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
43 lines
1 KiB
Python
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
|