ForcePilot/backend/package/yuxi/channels/contract/dtos/shared/cache.py
Kris 08617091dc refactor: 整理项目包结构与导入路径
- 新增多个业务域的__init__.py模块文件,规范包导出结构
- 调整多个DTO文件的导入路径,统一模块组织方式
- 移除测试文件中多余的空行与导入语句
- 优化部分业务模块的包层级划分
2026-07-18 02:04:03 +08:00

43 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""缓存 DTO。
定义缓存端口的值对象,包括锁令牌。所有 DTO 均为
``dataclass(frozen=True)``,仅依赖标准库,用于分布式锁管理。
"""
from __future__ import annotations
from dataclasses import dataclass
from datetime import datetime
from yuxi.channels.contract.errors import ValidationError
@dataclass(frozen=True)
class LockToken:
"""锁令牌。
标识一次分布式锁获取的令牌,携带锁键、令牌值与过期时间,用于锁续期与
释放校验。``key`` 字段使释放操作能从令牌还原锁键,避免适配器维护跨
请求的 ``token -> key`` 映射ADP-023 / INV-5
字段:
key: 锁键(获取时传入,释放时还原)。
value: 令牌值。
expires_at: 过期时间。
"""
key: str
value: str
expires_at: datetime
def __post_init__(self) -> None:
"""校验 key 与 value 非空。
``key`` 与 ``value`` 必须非空,在构造时即抛出 ``ValidationError``
避免空锁键或空令牌值导致锁释放校验失效INV-8
"""
if not self.key:
raise ValidationError("key", "must not be empty")
if not self.value:
raise ValidationError("value", "must not be empty")