Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jeroenbach opened this issue Sep 11, 2019 · 2 comments
Open

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

jeroenbach opened this issue Sep 11, 2019 · 2 comments

Comments

@jeroenbach
Copy link

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*/}});
@kuitos
Copy link
Owner

kuitos commented Feb 20, 2020

cool, feel free to submit a pr

@suhaotian
Copy link

You can add a custom axios request interceptor to fix this:

axios.interceptors.request.use(
      (config) => {
        config.params['__key'] = `[your id]`
        return config;
      });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants