@@ -15,9 +15,15 @@ export function defaultResponseInterceptor(axios: AxiosCacheInstance): ResponseI
1515 *
1616 * Also update the waiting list for this key by rejecting it.
1717 */
18- const rejectResponse = async ( responseId : string , config : CacheRequestConfig ) => {
18+ const rejectResponse = async (
19+ responseId : string ,
20+ config : CacheRequestConfig ,
21+ clearCache : boolean
22+ ) => {
1923 // Updates the cache to empty to prevent infinite loading state
20- await axios . storage . remove ( responseId , config ) ;
24+ if ( clearCache ) {
25+ await axios . storage . remove ( responseId , config ) ;
26+ }
2127
2228 // Rejects the deferred, if present
2329 const deferred = axios . waiting . get ( responseId ) ;
@@ -116,7 +122,7 @@ export function defaultResponseInterceptor(axios: AxiosCacheInstance): ResponseI
116122 ! cache . data &&
117123 ! ( await testCachePredicate ( response , cacheConfig . cachePredicate ) )
118124 ) {
119- await rejectResponse ( response . id , config ) ;
125+ await rejectResponse ( response . id , config , true ) ;
120126
121127 if ( __ACI_DEV__ ) {
122128 axios . debug ( {
@@ -154,7 +160,7 @@ export function defaultResponseInterceptor(axios: AxiosCacheInstance): ResponseI
154160
155161 // Cache should not be used
156162 if ( expirationTime === 'dont cache' ) {
157- await rejectResponse ( response . id , config ) ;
163+ await rejectResponse ( response . id , config , true ) ;
158164
159165 if ( __ACI_DEV__ ) {
160166 axios . debug ( {
@@ -276,7 +282,7 @@ export function defaultResponseInterceptor(axios: AxiosCacheInstance): ResponseI
276282 }
277283
278284 // Rejects all other requests waiting for this response
279- await rejectResponse ( id , config ) ;
285+ await rejectResponse ( id , config , true ) ;
280286
281287 throw error ;
282288 }
@@ -297,7 +303,12 @@ export function defaultResponseInterceptor(axios: AxiosCacheInstance): ResponseI
297303 }
298304
299305 // Rejects all other requests waiting for this response
300- await rejectResponse ( id , config ) ;
306+ await rejectResponse (
307+ id ,
308+ config ,
309+ // Do not clear cache if this request is cached, but the request was cancelled before returning the cached response
310+ error . code !== 'ERR_CANCELED' || ( error . code === 'ERR_CANCELED' && cache . state !== 'cached' )
311+ ) ;
301312
302313 throw error ;
303314 }
@@ -381,7 +392,7 @@ export function defaultResponseInterceptor(axios: AxiosCacheInstance): ResponseI
381392 }
382393
383394 // Rejects all other requests waiting for this response
384- await rejectResponse ( id , config ) ;
395+ await rejectResponse ( id , config , true ) ;
385396
386397 throw error ;
387398 } ;
0 commit comments