Skip to content

✨ Adding generateCacheKey to ApolloServerPluginResponseCache to allow for custom cache keys#6655

Merged
trevor-scheer merged 11 commits into
apollographql:release-3.10.0from
kschrade:main
Jul 11, 2022
Merged

✨ Adding generateCacheKey to ApolloServerPluginResponseCache to allow for custom cache keys#6655
trevor-scheer merged 11 commits into
apollographql:release-3.10.0from
kschrade:main

Conversation

@kschrade

@kschrade kschrade commented Jul 8, 2022

Copy link
Copy Markdown
Contributor

Create a new hook (generateCacheKey) on the ApolloServerPluginResponseCache
constructor options which allows users to customize the cache key used by returning
their own string.

The hook receives two arguments: the requestContext and an object (cacheKeyData)
which contains the following properties:
source
operationName
variables
extra (computed by options.extraCacheKeyData)
sessionId
sessionMode

Landing in favor of:
#6649
#6428

@changeset-bot

changeset-bot Bot commented Jul 8, 2022

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 1c84a40

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify

netlify Bot commented Jul 8, 2022

Copy link
Copy Markdown

Deploy Preview for apollo-server-docs canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 1c84a40
🔍 Latest deploy log https://app.netlify.com/sites/apollo-server-docs/deploys/62cc6c6708e25e0009981662

@codesandbox-ci

codesandbox-ci Bot commented Jul 8, 2022

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1c84a40:

Sandbox Source
Apollo Server Typescript Configuration
Apollo Server Configuration

@glasser glasser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also provide at least a brief mention of this parameter in the docs (docs/source/performance/caching.md). The table in the bottom section seems reasonable. Thanks1

@kschrade kschrade requested a review from glasser July 8, 2022 18:59
Comment thread docs/source/performance/caching.md Outdated
@kschrade kschrade requested a review from glasser July 11, 2022 17:06
…luginResponseCache.ts

Co-authored-by: Trevor Scheer <trevor.scheer@gmail.com>

@trevor-scheer trevor-scheer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Would you please make an addition to CHANGELOG.md?

@trevor-scheer trevor-scheer changed the base branch from main to release-3.10.0 July 11, 2022 18:32
@kschrade kschrade changed the title ✨ Adding new hook for changing the cachekey for the response cache ✨ Adding generateCacheKey to ApolloServerPluginResponseCache to allow for custom cache keys Jul 11, 2022
@trevor-scheer trevor-scheer merged commit 7d6d3ce into apollographql:release-3.10.0 Jul 11, 2022
glasser added a commit that referenced this pull request Jul 11, 2022
- Rename BaseCacheKey and ContextualCacheKey with "Data" on end, since
  the cache key is a string.
- Reintroduce CacheKey(Data) removed in #6655; make the
  GenerateCacheKeyFunction type be defined in terms of it. Now calls to
  the `const generateCacheKey` function are type-safe (ie, the second
  arg is a CacheKeyData rather than unknown).
- Describe generateCacheKey hook as a method rather than a field, like
  the other hooks in Options.
@glasser glasser mentioned this pull request Jul 11, 2022
trevor-scheer pushed a commit that referenced this pull request Jul 11, 2022
- Rename BaseCacheKey and ContextualCacheKey with "Data" on end, since
  the cache key is a string.
- Reintroduce CacheKey(Data) removed in #6655; make the
  GenerateCacheKeyFunction type be defined in terms of it. Now calls to
  the `const generateCacheKey` function are type-safe (ie, the second
  arg is a CacheKeyData rather than unknown).
- Describe generateCacheKey hook as a method rather than a field, like
  the other hooks in Options.
trevor-scheer pushed a commit that referenced this pull request Jul 11, 2022
…for custom cache keys (#6655)

Create a new hook (`generateCacheKey`) on the `ApolloServerPluginResponseCache`
constructor options which allows users to customize the cache key used by returning
their own `string`.

The hook receives two arguments: the `requestContext` and an object (`cacheKeyData`)
which contains the following properties:
`source`
`operationName`
`variables`
`extra` (computed by `options.extraCacheKeyData`)
`sessionId`
`sessionMode`
trevor-scheer pushed a commit that referenced this pull request Jul 11, 2022
- Rename BaseCacheKey and ContextualCacheKey with "Data" on end, since
  the cache key is a string.
- Reintroduce CacheKey(Data) removed in #6655; make the
  GenerateCacheKeyFunction type be defined in terms of it. Now calls to
  the `const generateCacheKey` function are type-safe (ie, the second
  arg is a CacheKeyData rather than unknown).
- Describe generateCacheKey hook as a method rather than a field, like
  the other hooks in Options.
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants