fix: reject REDIS_CACHE_TTL<=0 (kill implicit never-expire)
This commit is contained in:
@@ -12,6 +12,26 @@ from loguru import logger
|
||||
from core.types import LLMResponse
|
||||
|
||||
|
||||
def _resolve_cache_ttl(ttl: int) -> int:
|
||||
"""校验 Redis 缓存 TTL:必须为正整数(消灭 0=永不过期 的隐式语义)。
|
||||
|
||||
Args:
|
||||
ttl: 待校验的 TTL 秒数。
|
||||
|
||||
Returns:
|
||||
校验通过的正整数 TTL。
|
||||
|
||||
Raises:
|
||||
ValueError: ttl <= 0。
|
||||
"""
|
||||
if ttl <= 0:
|
||||
raise ValueError(
|
||||
f"REDIS_CACHE_TTL 必须为正整数秒,实际 {ttl}。"
|
||||
"训练场景建议 >= 单次训练时长(如 86400)。"
|
||||
)
|
||||
return ttl
|
||||
|
||||
|
||||
class RedisResponseCache:
|
||||
"""基于 Redis 的 LLM 响应缓存。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user