Skip to content

perf: 订阅 serve 缓存改为内容寻址(失效驱动,不再按 TTL 重跑引擎) - #34

Merged
lr00rl merged 1 commit into
mainfrom
perf/serve-cache-revalidation
Aug 12, 2026
Merged

perf: 订阅 serve 缓存改为内容寻址(失效驱动,不再按 TTL 重跑引擎)#34
lr00rl merged 1 commit into
mainfrom
perf/serve-cache-revalidation

Conversation

@lr00rl

@lr00rl lr00rl commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

问题(生产实测)

渲染缓存 300s 过期即重渲染;重渲染=冷启动插件 JS 引擎,脚本文件实测 13.5s、组合 12.6s。任何轮询间隔超过 5 分钟的客户端,每次拉取都付全价。

改动

  • TTL 300s→30min,语义变为"再验证节拍"(与快照刷新间隔对齐):过期先刷新快照(便宜,不起引擎),内容摘要没变→延长缓存不重渲染;变了→渲染一次。
  • 源不可达→服务旧内容(stale-if-error),与快照层"provider 挂了不清空客户端配置"的规则一致。
  • 失效改由事件驱动:刷新拿到新字节→失效该源的分享;管理面 save/delete/import/migrate 成功→失效该插件的分享(编辑改变渲染结果但不变内容摘要,TTL 看不见)。
  • Get 过期不再顺手删除(revalidation 需要读旧条目;LRU 与 Put 负责回收)。

配套插件 PR #17:fetch 覆盖全部记录种类,组合/文件从此可分享,且渲染端消费快照后稳态 serve 只需 1-2 次 host 调用。

Test plan

  • go test ./internal/server 全量绿(新增再验证/失效/替换测试)
  • CI
  • 生产:分享轮询计时对比(首拉 vs 30 分钟后再拉)

A rendered body used to live for 300s and then be re-rendered no matter
what — every re-render boots the plugin's JavaScript engine, measured at
13.5s on production for a script-built file, so any client polling slower
than the TTL paid that on every single poll.

The TTL is now a revalidation cadence (30m, aligned with the snapshot
refresh interval), not a lifetime. On expiry the serve path refreshes the
snapshot — cheap, no engine — and compares content digests: unchanged
extends the cached body, changed re-renders once. A source that cannot be
reached serves the last good body instead of an error, mirroring the
snapshot layer's keep-the-client's-config rule one step down.

Invalidation is event-driven where the TTL could not see change: a refresh
that returns different bytes drops the shares sourcing that record, and a
successful save/delete/import/migrate through the plugin's management API
drops the shares sourcing that plugin's store — an edit changes what a
record renders without changing any content hash.
@lr00rl
lr00rl merged commit e88677a into main Aug 12, 2026
1 check passed
@lr00rl
lr00rl deleted the perf/serve-cache-revalidation branch August 12, 2026 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant