You might have seen our documentation on requestsCache and responseCache and thought, how do these two caches work? What would happen if I set one to InMemoryCache and the other to NullCache?
The full functionality can be seen in our source code but this is the general flow of what's happening behind the scenes.
- First, we compute the user request options.
- Then, we prepare a function factory
createRetryableRequest()
that contains the construction of the retryAble request. - If requestsCache is set with
createNullCache()
then we trigger the retryAble request and no further evaluations will be made. If requestsCache is set withcreateInMemoryCache()
then we move to the next step. - If the requestsCache is cacheable the key for the current request will be computed.
- This key will be used to ask the responsesCache implementation if this request has been resolved before.
- If the request has never been resolved before, we check the requestsCache to see if there is a current request with the same key in progress.
- Finally, if there is no request in progress with the same key, this
createRetryableRequest()
will actually trigger the retryableRequest.
The requestsCache handles caching of the request keys that contains the user request options (query parameters, headers, etc). If it cannot be cached because { requestsCache: createNullCache } then the retryAble request will be triggered and no further cache checks will be made.
If { requestsCache: createInMemoryCache, responseCache: createNullCache } were set then the result would be that responsesCache would never find a key matching a resolved request in its cache, but requestsCache would still check if there is a current request with the same key in progress. If no request in progress with the same key then the retryAble request would be triggered.
This evaluation of whether there is a request in progress with the same key would be the only real difference between { requestsCache: createInMemoryCache, responseCache: createNullCache } and { requestsCache: createNullCache, responseCache: createNullCache }.
We do not recommend mismatching the requests and response cache settings as there are no real benefits to this and it may cause errors.