Description
Background
Specifying the same fixedCacheKey
across mutations leads to overlapping caches between the two mutations. While the fix for this is as simple as properly ensuring cache keys are not repeated across mutations, it is a bug that can easily be run into.
Should fixedCacheKey
's have this behavior, or should it result in a mutation cache specific to the endpoint it is provided for?
Example
export function useTransaction(transactionId: string) {
const [createQuote, quoteResult] =
api.endpoints.createQuote.useMutation({
fixedCacheKey: transactionId
})
const [initiateTransaction, transactionResult] =
chipperAirtimeApi.endpoints.airtimePurchase.useMutation({
fixedCacheKey: transactionId
})
// BUG: purchaseResult == quoteResult after either `createQuote` or `initiateTransaction` is called,
// but ideally should each be different?
return {
getQuote,
quoteResult,
initiateTransaction,
transactionResult
}
}
Potential Solution
export function useTransaction(transactionId: string) {
const [createQuote, quoteResult] =
api.endpoints.createQuote.useMutation({
fixedCacheKey: transactionId + ':quote'
})
const [initiateTransaction, transactionResult] =
chipperAirtimeApi.endpoints.initiateTransaction.useMutation({
fixedCacheKey: transactionId + ':initiate'
})
...
Desired Outcome
The desired outcome should be that the same cache key can be used across endpoints without their caches overlapping since they are separate endpoints.
Having diagnosed and found a solution to the problem, it is no longer a pressing issue, however, it would be lovely if it worked as expected and if it aligns with the library's goals! Thanks, and happy to help resolve.
RTK Version
1.9.0
PS: I'll be back with a demo/repro to assist, but wanted to drop this here for now.