mirror of
https://github.com/arthurfiorette/axios-cache-interceptor.git
synced 2025-12-08 17:36:16 +00:00
docs: updated keyGenerator info
This commit is contained in:
parent
9379fce100
commit
3c8b373d51
@ -45,21 +45,20 @@ property.
|
||||
By default, it uses the `method`, `baseURL`, `params`, `data` and `url` properties from
|
||||
the request object into an hashcode generated by the `object-code` library.
|
||||
|
||||
You can make two "different" requests share the same cache with this property.
|
||||
|
||||
An example:
|
||||
If you need to change or share the cache for two requests based on other properties, like
|
||||
headers and etc, you can create your own Key Generator:
|
||||
|
||||
```js #runkit
|
||||
const axios = require('axios');
|
||||
const { setupCache, buildKeyGenerator } = require('axios-cache-interceptor');
|
||||
|
||||
const generator = buildKeyGenerator(({ headers }) => {
|
||||
const generator = buildKeyGenerator(({ headers = {} }) => {
|
||||
// In this imaginary example, two requests will
|
||||
// be treated as the same if their x-cache-server header is the same.
|
||||
|
||||
// The result of this function, being a object or not, will be
|
||||
// hashed by `object-code` library.
|
||||
return headers?.['x-cache-server'] || 'not-set';
|
||||
return headers['x-cache-server'] || 'not-set';
|
||||
});
|
||||
|
||||
const axios = mockAxios({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user