Skip to content

Commit

Permalink
docs: updated keyGenerator info
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Jan 14, 2022
1 parent 9379fce commit 3c8b373
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions docs/pages/request-id.md
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 3c8b373

Please sign in to comment.