axios-extensions icon indicating copy to clipboard operation
axios-extensions copied to clipboard

Adding a possibility to have a custom cache-key generator.

Open jeroenbach opened this issue 4 years ago • 2 comments

In our API calls we pass a languageid & siteid as header data, which will give us different results. For this it would be handy for us to allow passing a custom cachekey generator with the options.

Do you agree with this idea? If yes, then we can also create a Pull Request with this change if you don't have time to add it?

In throttleAdapterEnhancer & cacheAdapterEnhancer:

var customCacheKey = options.cacheKeyGenerator && options.cacheKeyGenerator(config, buildSortedURL(url, params, paramsSerializer));
var index_1 = customCacheKey || buildSortedURL(url, params, paramsSerializer);

and then in the calling method we can pass the cacheKeyGenerator to the options.

cacheAdapterEnhancer(axios.defaults.adapter, { cacheKeyGenerator: (config, originalKey) => { /*custom logic*/}});

jeroenbach avatar Sep 11 '19 15:09 jeroenbach

cool, feel free to submit a pr

kuitos avatar Feb 20 '20 05:02 kuitos