Transform response before caching #771
-
There are times when I don't want to cache the full response as its too big (causing memory pressure) and I only need few data point from response for my further use. is it possible to transform my response data before it is saved in the cache and return the transformed data as part of axios response. I tried using axios response interceptor but all other axios response (non cached) also intercepted and it difficult to keep separation between the different calls. can I defined some data mapper while creating a cached axios instance? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey @amrendr-cb, currently this is not possible by default, you may make this work by applying your own interceptor that maps the response before the axios-cache-interceptor's interceptor run. However, this would be an awesome feature, are you open to a PR? |
Beta Was this translation helpful? Give feedback.
We can use the
transformResponse
API of Axios to provide our transformation method. After data transformation, the cache interceptor stores the transformed data in the cache.With the fix #775, the cache interceptor no longer runs
transformResponse
twice on cached requests, which was causing unintended responses.