Skip to content

Commit

Permalink
Two unrelated small cache improvements (#7241)
Browse files Browse the repository at this point in the history
- Explicitly allow people to pass `cache: 'bounded'`. Non-TS users
upgrading from the recommended AS3.9+ configuration could do this by
accident. Fixes #7240.

- Upgrade `@apollo/utils.keyvaluecache` so that the new
`PrefixingKeyValueCache.cacheDangerouslyDoesNotNeedPrefixesForIsolation`
feature lets you disable prefixing for the APQ and full response caches.
Throw if you try to pass such a cache to `ApolloServer` itself because
that cache is designed to be shared across features. Migrate off of
PrefixingKeyValueCache for `documentStore` so that its prefixing can't
be disabled. Fixes #6742.
  • Loading branch information
glasser committed Dec 12, 2022
1 parent f0fcdac commit d7e9b97
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 88 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-eyes-chew.md
@@ -0,0 +1,5 @@
---
'@apollo/server-plugin-response-cache': minor
---

If the cache you provide to the `cache` option is created with `PrefixingKeyValueCache.cacheDangerouslyDoesNotNeedPrefixesForIsolation` (new in `@apollo/utils.keyvaluecache@2.1.0`), the `fqc:` prefix will not be added to cache keys.
5 changes: 5 additions & 0 deletions .changeset/selfish-buckets-mate.md
@@ -0,0 +1,5 @@
---
'@apollo/server': minor
---

If the cache you provide to the `persistedQueries.cache` option is created with `PrefixingKeyValueCache.cacheDangerouslyDoesNotNeedPrefixesForIsolation` (new in `@apollo/utils.keyvaluecache@2.1.0`), the `apq:` prefix will not be added to cache keys. Providing such a cache to `new ApolloServer()` throws an error.
5 changes: 5 additions & 0 deletions .changeset/sour-kiwis-eat.md
@@ -0,0 +1,5 @@
---
'@apollo/server': patch
---

For ease of upgrade from the recommended configuration of Apollo Server v3.9+, you can now pass `new ApolloServer({ cache: 'bounded' })`, which is equivalent to not providing the `cache` option (as a bounded cache is now the default in AS4).
2 changes: 1 addition & 1 deletion docs/source/api/apollo-server.mdx
Expand Up @@ -353,7 +353,7 @@ Controls whether to allow [Batching Queries](../workflow/requests/#batching) in

A [`KeyValueCache`](https://www.npmjs.com/package/@apollo/utils.keyvaluecache) which Apollo Server uses for several features, including APQs and full response caching. This cache is also available to Apollo Server's plugins.

The default cache is an [`InMemoryLRUCache`](https://www.npmjs.com/package/@apollo/utils.keyvaluecache) with a default size of roughly 30MiB.
The default cache is an [`InMemoryLRUCache`](https://www.npmjs.com/package/@apollo/utils.keyvaluecache) with a default size of roughly 30MiB. (For backwards-compatibility with Apollo Server 3, specifying `cache: 'bounded'` also selects this default bounded cache.)

To learn more about configuring Apollo Server's cache, see [Configuring cache backends](../performance/cache-backends).

Expand Down
207 changes: 136 additions & 71 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/gateway-interface/package.json
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@apollo/utils.fetcher": "^2.0.0",
"@apollo/utils.logger": "^2.0.0",
"@apollo/utils.keyvaluecache": "^2.0.1",
"@apollo/utils.keyvaluecache": "^2.1.0",
"@apollo/usage-reporting-protobuf": "^4.0.0"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/integration-testsuite/package.json
Expand Up @@ -30,7 +30,7 @@
"@apollo/client": "^3.6.9",
"@apollo/server": "4.2.2",
"@apollo/server-plugin-landing-page-graphql-playground": "^4.0.0",
"@apollo/utils.keyvaluecache": "^2.0.1",
"@apollo/utils.keyvaluecache": "^2.1.0",
"@apollo/utils.createhash": "^2.0.0",
"@apollo/usage-reporting-protobuf": "^4.0.0",
"@josephg/resolvable": "^1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-response-cache/package.json
Expand Up @@ -30,7 +30,7 @@
},
"dependencies": {
"@apollo/utils.createhash": "^2.0.0",
"@apollo/utils.keyvaluecache": "^2.0.1"
"@apollo/utils.keyvaluecache": "^2.1.0"
},
"peerDependencies": {
"@apollo/server": "^4.0.1",
Expand Down

0 comments on commit d7e9b97

Please sign in to comment.