apollo-server
apollo-server copied to clipboard
Add Dynamic Prefix To Cache Key
Adding hook to pass a function with access to request context to return a dynamic prefix for each key. This feature allows the developers to pass identifiers to the keys, so it makes it searchable for redis-cli or memcached that use key-based searches.
@jorgechacon04: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/
Deploy Preview for apollo-server-docs canceled.
Built without sensitive environment variables
Name | Link |
---|---|
Latest commit | c29bec46d2f95a1085534c05757ef1bda002addb |
Latest deploy log | https://app.netlify.com/sites/apollo-server-docs/deploys/628e68091576fb0008d5b8e4 |
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 c29bec46d2f95a1085534c05757ef1bda002addb:
Sandbox | Source |
---|---|
Apollo Server Typescript | Configuration |
Apollo Server | Configuration |
Would it make more sense to let you override cacheKeyString
instead? (Note that this would also subsume the functionality of extraCacheKeyData
which could be deprecated.)
@glasser That sounds good too, however at least for our case extraCacheKeyData is not used, because that will be hashed so it is not searchable for redis
I added a new hook, to be able to share the requestContext to extract data like operationName, etc
I think I might not have been clear here. I feel like the concept of "dynamic prefix" is too specific. Both "dynamic prefix" and "extra cache key data" are ways to influence the calculation of the cache key, and it would make more sense to just let you define a "calculate the cache key" hook instead of providing more ad hoc tweaks to the existing one. Happy to review and merge a PR that does this more general change (which would also let us deprecate extraCacheKeyData and drop it in AS4) rather than this more specific one.
We released a similar feature (generateCacheKey
) in AS v3.10.0. Thanks for the inspiration!