xiaozhi-esp32-server/main/xiaozhi-server/core/utils/cache/config.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

66 lines
2.3 KiB
Python

"""
Cache configuration management.
"""
from enum import Enum
from typing import Dict, Any, Optional
from dataclasses import dataclass
from .strategies import CacheStrategy
class CacheType(Enum):
"""Supported cache type definitions."""
LOCATION = "location"
WEATHER = "weather"
LUNAR = "lunar"
INTENT = "intent"
IP_INFO = "ip_info"
CONFIG = "config"
DEVICE_PROMPT = "device_prompt"
VOICEPRINT_HEALTH = "voiceprint_health" # Voiceprint health-check cache.
AUDIO_DATA = "audio_data" # Audio data cache.
@dataclass
class CacheConfig:
"""Cache configuration."""
strategy: CacheStrategy = CacheStrategy.TTL
ttl: Optional[float] = 300 # Default: 5 minutes.
max_size: Optional[int] = 1000 # Default: 1000 entries.
cleanup_interval: float = 60 # Cleanup interval in seconds.
@classmethod
def for_type(cls, cache_type: CacheType) -> "CacheConfig":
"""Return the preset configuration for a cache type."""
configs = {
CacheType.LOCATION: cls(
strategy=CacheStrategy.TTL, ttl=None, max_size=1000 # Manually invalidated.
),
CacheType.IP_INFO: cls(
strategy=CacheStrategy.TTL, ttl=86400, max_size=1000 # 24 hours.
),
CacheType.WEATHER: cls(
strategy=CacheStrategy.TTL, ttl=28800, max_size=1000 # 8 hours.
),
CacheType.LUNAR: cls(
strategy=CacheStrategy.TTL, ttl=2592000, max_size=365 # 30 days.
),
CacheType.INTENT: cls(
strategy=CacheStrategy.TTL_LRU, ttl=600, max_size=1000 # 10 minutes.
),
CacheType.CONFIG: cls(
strategy=CacheStrategy.FIXED_SIZE, ttl=None, max_size=20 # Manually invalidated.
),
CacheType.DEVICE_PROMPT: cls(
strategy=CacheStrategy.TTL, ttl=None, max_size=1000 # Manually invalidated.
),
CacheType.VOICEPRINT_HEALTH: cls(
strategy=CacheStrategy.TTL, ttl=600, max_size=100 # 10 minutes.
),
CacheType.AUDIO_DATA: cls(
strategy=CacheStrategy.TTL, ttl=600, max_size=100 # 10 minutes.
),
}
return configs.get(cache_type, cls())