Skip to content

Commit b7aa530

Browse files
authored
Docs: Comparison table for different use cases of @cacheControl (#6395)
1 parent 7ba1a91 commit b7aa530

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

packages/web/docs/src/pages/docs/gateway/other-features/performance/http-caching.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ can enable HTTP caching in your Hive Gateway by using the HTTP caching plugin. T
1111
cache the responses when possible, and reduce the server load. It uses
1212
[`http-cache-semantics`](https://www.npmjs.com/package/http-cache-semantics) under the hood.
1313

14+
It is useful when you use it with
15+
[Yoga's Response Caching](https://the-guild.dev/graphql/yoga-server/docs/features/response-caching#http-caching-via-etag-and-if-none-match-headers)
16+
or
17+
[Apollo Server's Response Caching](https://www.apollographql.com/docs/apollo-server/performance/caching/).
18+
1419
<Callout>
1520
You need to set your cache storage in your gateway configuration to enable response caching. See
1621
[Cache Storage](/docs/gateway/other-features/performance#providing-cache-storage) for more

packages/web/docs/src/pages/docs/gateway/other-features/performance/response-caching.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,18 @@ flowchart TD
261261
A ---|"Send GraphQL Request via HTTP "| n6
262262
```
263263

264+
#### Overall comparison
265+
266+
| Usage of `@cacheControl` | No HTTP Calls for cached results | Invalidation via mutations | | |
267+
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | --- | --- |
268+
| Subgraph on [Apollo Server with Response Cache Plugin](https://www.apollographql.com/docs/apollo-server/performance/caching/)<br/><br/>Uses HTTP `Cache-Control` header & [Gateway HTTP Cache Plugin](/docs/gateway/other-features/performance/http-caching) | 🟢 - Fully done<br/>Until TTL expires given in `Cache-Control` HTTP header, no HTTP calls are made in the following GraphQL requests.<br/>So the number of HTTP requests reduce. | 🔴 - Not available<br/>Until TTL expires or cache is reset manually on the gateway,<br/>it is not possible to invalidate it automatically. | | |
269+
| Subgraph on [Yoga Server with Response Cache Plugin](https://the-guild.dev/graphql/yoga-server/docs/features/response-caching#http-caching-via-etag-and-if-none-match-headers)<br/><br/>Uses HTTP `ETag` header & [Gateway HTTP Cache Plugin](/docs/gateway/other-features/performance/http-caching) | 🟠 - Partially done<br/>Until TTL expires, it validates via an HTTP request with held `ETag` value on each GraphQL request, <br/>and returns 304 without body.<br/>So the number of HTTP requests do not reduce, but the load in the traffic reduces. | 🟢 - Fully done<br/><br/>In case of fetched new value, ETag value changes so that the gateway can invalidate the cached response | | |
270+
| `@cacheControl` with `@composeDirective`<br/><br/>Uses Gateway Response Caching Plugin | 🟢 - Fully done<br/>Until TTL expires given in `@cacheControl` directive, no HTTP calls are made in the following GraphQL requests.<br/>So the number of HTTP requests reduce. | 🟢 - Fully done<br/>In case of the fetched new value, the cache is directly invalidated by the gateway | | |
271+
272+
In order to avoid extra HTTP calls, and invalidate the responses automatically via mutations, it'd
273+
recommended to use the `@cacheControl` directive with the `@composeDirective` in the subgraphs
274+
together with this plugin.
275+
264276
## Session based caching
265277

266278
If your GraphQL API returns specific data depending on the viewer's session, you can use the session

0 commit comments

Comments
 (0)