-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(compute-key): add support for mapKeyToCacheKey #71
Conversation
this option allows consumers to directly vary their cache key
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 a693a07:
|
Co-authored-by: Matthew Mallimo <matthew.c.mallimo@aexp.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you include a test that does a transform on the key instead of just replacing it?
Co-authored-by: Jamie King <jamie.king@aexp.com>
Co-authored-by: Jamie King <jamie.king@aexp.com>
@@ -58,4 +67,55 @@ describe('computeKey', () => { | |||
}; | |||
expect(computeKey('uri', firstOptions).hash).toBe(computeKey('uri', secondOptions).hash); | |||
}); | |||
|
|||
it('should return a different, stable hash, if the option mapKeyToCacheKey is passed', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test cannot assert that the key is different as the spec states since it only generates one key. There is nothing to compare it to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in a693a07
expect(computeHash).toHaveBeenCalledWith(['ABCD-optionKeyValue', { optionKeyMock: 'optionKeyValue' }], { respectType: false }); | ||
}); | ||
|
||
it('should return the same key if the option mapKeyToCacheKey returns the same string as the key', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test has the same issue as the one on line 71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in a693a07
@code-forger , thanks this is very promising. how does this work with the SSR request? namely, const fetchye = makeOneServerFetchye({ store, fetchClient }); is |
this option allows consumers to directly vary their cache key
Motivation and Context
This change enables more advanced caching features, where the cached data is not directly tied to a single complete url.
How Has This Been Tested?
unit tests, run locally in a module.
This is a non-breaking change. No existing unit test was changed of fails.
Types of Changes
Checklist:
What is the Impact to Developers Using Fetchye?
New functionality