Skip to content

Latest commit

 

History

History
80 lines (42 loc) · 1.82 KB

File metadata and controls

80 lines (42 loc) · 1.82 KB

graphQL Cache - 2020/03/11

tags: tech workshop

目標

如何利用 cache 加快 seeker query 的時間

Browser, CDN, Reverse Proxy, Server-side Cache

Cache with GraphQL

POST /graphql

  • 其實 HTTP spec 沒有限制 POST method 不能 cache,只是在 cache 的地方 (E.g. nginx) 要設定好

但是

  • 意思是說幾乎全部的 cache 預設都不支援 POST

change POST to GET /graphql

graphQL cache 相比 REST 的限制

  • 在上面的 query,即便有共用 friends 的 name、birthday 欄位,依舊會被認為是不同的 query 而無法 cache

  • 在彈性上做取捨

Caching with Apollo Server

https://www.apollographql.com/docs/apollo-server/performance/caching/

https://github.com/apollographql/apollo-server/tree/master/packages/apollo-server-plugin-response-cache

demo

Cache-Control

https://blog.techbridge.cc/2017/06/17/cache-introduction/

header 有了 Cache-Control 就能在上面不同的層級做 cache