知识卡片
缓存契约权衡新鲜度
服务依赖远端数据时,网络延迟与故障会降低可用性,完全绕过缓存又会增加负载。
缓存需要供需双方配合:提供方声明可缓存范围与新鲜期限,消费方遵守,并按用途提出可接受的新鲜度。静态列表可缓存较久,易变数据应缩短期限;准备编辑时尤其需要重新验证。
典型配置Cache-Control: private, max-age=600表达私有缓存与期限;no-cache要求使用前验证,不能理解为禁止存储。选择接受旧副本的策略应限于业务允许的读取。还要考虑Vary所指的协商维度,避免把错误语言、身份或表示的副本回放。书中缓存报文有简化之处,部署时需按实际协议规则确定组合。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 分布式数据 · 查看原书依据
When your service interface relies on other, remote, services for data, the easiest way to improve perceived performance is by leveraging the HTTP caching models built into the protocol. That means service providers need to mark every response with caching metadata to help consumers understand the lifetime of the response.
参考来源
- 位置:《RESTful Web API Patterns and Practices Cookbook Connecting and Orchestrating Microservices and Distributed Data (Mike Amundsen)》第6章《分布式数据》§6.9(来源项目:book-sources;源文件:extracted/RESTful Web API Patterns and Practices Cookbook Connecting and Orchestrating Microservices and Distributed Data (Mike Amundsen)/_epub-src/OEBPS/ch06.xhtml)
- 结论依据:原文以缓存需要供需双方配合:提供方声明可缓存范围与新鲜期限,消费方遵守,并按用途提出可接受的新鲜度的方式说明该用途;同节示例与讨论补充了卡内条件和边界。
- 原始内容:When your service interface relies on other, remote, services for data, the easiest way to improve perceived performance is by leveraging the HTTP caching models built into the protocol. That means service providers need to mark every response with caching metadata to help consumers understand the lifetime of the response.