mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-27 04:49:47 +01:00
- hass_state: use httpx (async) instead of undefined requests/asyncio.TimeoutError - prompt_manager: call sync get_weather directly on executor thread; drop lunar plumbing - register: repopulate module_func_map so module-level plugins expand to functions - whisper/kokoro: run blocking transcribe/HTTP calls via asyncio.to_thread - edge TTS: re-apply volume/rate/pitch percentage params; elevenlabs: pass voice_settings - add GeminiVLLM provider (google-genai) backing the GeminiVLLM config entry - get_news: dedicated NEWS cache (15m) and live Western RSS defaults; drop dead newsnow branch - play_music: return Action.RECORD so playback turns enter dialogue history - ota_handler: default timezone_offset 0; config: prompt_template, HA entities, voice, language - agent-base-prompt.txt: rebuilt from upstream engineered English baseline - tests: drop shims/expectations for providers removed by the western provider set
66 lines
2.3 KiB
Python
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"
|
|
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.
|
|
NEWS = "news" # Latest-news brief cache (short TTL; news goes stale fast).
|
|
|
|
|
|
@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.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.
|
|
),
|
|
CacheType.NEWS: cls(
|
|
strategy=CacheStrategy.TTL, ttl=900, max_size=200 # 15 minutes.
|
|
),
|
|
}
|
|
return configs.get(cache_type, cls())
|