Files
any-hub/specs/007-apt-apk-cache/data-model.md
2025-11-18 09:55:07 +08:00

37 lines
1.9 KiB
Markdown
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.
# Data Model: APT/APK 包缓存模块
## Entities
### HubConfig (APT/APK)
- Fields: `Name`, `Domain`, `Port`, `Upstream`, `Type` (`debian`/`apk`), optional `CacheTTL` override.
- Rules: `Type` 必须新增枚举;`Upstream` 必须为 HTTP/HTTPS每个 Hub 独立缓存前缀。
### IndexFile
- Represents: APT Release/InRelease/Packages*Alpine APKINDEX。
- Attributes: `Path`, `ETag` (if present), `Last-Modified`, `Hash` (if provided in index), `Size`, `ContentType`.
- Rules: RequireRevalidate=true缓存命中需携带条件请求内容不得修改。
### PackageFile
- Represents: APT `pool/*/*.deb` 包体Alpine `packages/<arch>/*.apk`
- Attributes: `Path`, `Size`, `Hash` (from upstream metadata if available), `StoredAt`.
- Rules: 视作不可变AllowCache/AllowStore=true不做本地内容改写。
### SignatureFile
- Represents: APT `Release.gpg`/`InRelease` 自带签名Alpine APKINDEX 签名文件。
- Attributes: `Path`, `Size`, `StoredAt`.
- Rules: 原样透传;与对应 IndexFile 绑定,同步缓存与再验证。
### CacheEntry
- Represents: 本地缓存记录(索引或包体)。
- Attributes: `LocatorPath`, `ModTime`, `ETag`, `Size`, `AllowStore`, `RequireRevalidate`.
- Rules: 读取时决定是否回源;写入需同步 `.meta`;路径格式 `StoragePath/<Hub>/<Path>`.
## Relationships
- HubConfig → IndexFile/PackageFile/SignatureFile 通过 Domain/Upstream 绑定。
- IndexFile ↔ SignatureFile同一索引文件的签名文件需同周期缓存与再验证。
- CacheEntry 聚合 IndexFile/PackageFile/SignatureFile 的落盘信息,用于策略判定。
## State/Transitions
- CacheEntry states: `miss``fetched``validated` (304) / `refreshed` (200) → `stale` (TTL 或上游 200 新内容) → `removed` (404 或清理)。
- Transitions triggered by upstream响应304 保持内容200 刷新404 删除相关缓存。