知识卡片

普通读书笔记卡 · 3476

可缓存响应减少重复计算

理解等级:中级

可缓存的 API 响应可以在有效期内复用,避免每次请求都重新取数或计算。书中以短时缓存订单状态为例,减少向厨房服务的重复查询;缓存是否适合仍取决于响应变化速度与允许的陈旧程度。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    原书出处

    参考来源

    - 位置:《Microservice APIs》第 4 章《Principles of REST API design》(源文件:_epub-src/OEBPS/Text/04.htm) - 结论依据:原文说明缓存可避免重复计算和回源,并用订单状态短期缓存示例解释其性能收益。 - 原始内容:Caching improves the performance of APIs because it means we don’t have to perform all the calculations required to serve a response again and again. GET requests are suitable for caching, since they return data already saved in the server. ... To save time the next time the customer checks the order’s status, we cache its value for a short period of time.