Open
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
Introduces an optional requestCacheKey suffix to all generated Redis cache keys and propagates it through the schema resolution cache lookup.
- Add
requestCacheKeyparameter togenerateRedisKeyandgetCachein the caching layer. - Append the custom cache key fragment when building the Redis key.
- Pass
requestCacheKeyfrom the GraphQL resolver into the cache check inSchemaBuilder.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/cache/caching.js | Updated generateRedisKey and getCache signatures to accept requestCacheKey and append it to the final key. |
| lib/SchemaBuilder.js | Modified _checkCache call to forward request.req.requestCacheKey into the new cache methods. |
Comments suppressed due to low confidence (5)
lib/cache/caching.js:50
- Consider adding or updating JSDoc comments to describe the new
requestCacheKeyparameter and its effect on the generated key.
generateRedisKey(request, requestCacheKey) {
lib/cache/caching.js:63
- Update or add JSDoc on
getCacheto reflect the addedrequestCacheKeyparameter and how it alters cache lookups.
async getCache(request, requestCacheKey) {
lib/cache/caching.js:1
- Check other cache methods (e.g.,
setCache,deleteCache) for consistency: they may also need to acceptrequestCacheKeyso all operations use the same key format.
class Cache {
lib/cache/caching.js:55
- There are no existing tests for the new
requestCacheKeypath. Add unit tests to verify key generation with and without a custom prefix.
const cacheKey = requestCacheKey ? `_${requestCacheKey}` : ''
lib/SchemaBuilder.js:304
- Accessing
request.req.requestCacheKeywithout optional chaining could throw ifrequest.reqis undefined. Consider usingrequest?.req?.requestCacheKey.
const cached = await this._checkCache(cacheKeyElements, request.req.requestCacheKey)
Comment on lines
+54
to
+57
|
|
||
| const cacheKey = requestCacheKey ? `_${requestCacheKey}` : '' | ||
|
|
||
| return `${this.redisKeyPrefix}${cacheKey}_${md5(JSON.stringify(bodyData))}` |
There was a problem hiding this comment.
[nitpick] You could simplify the underscore logic by building an array of segments and joining with underscores, e.g., [this.redisKeyPrefix, requestCacheKey, md5(...)] after filtering out empty values.
Suggested change
| const cacheKey = requestCacheKey ? `_${requestCacheKey}` : '' | |
| return `${this.redisKeyPrefix}${cacheKey}_${md5(JSON.stringify(bodyData))}` | |
| const segments = [ | |
| this.redisKeyPrefix, | |
| requestCacheKey, | |
| md5(JSON.stringify(bodyData)) | |
| ].filter(Boolean) | |
| return segments.join('_') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Summary
requestCacheKey. Note thatrequestCacheKeyshould be set in thereqobject itself (that is,req.requestCacheKey).Ticket Link
TICKET LINK
Type of change
Checklist: