docs: updated readme example

This commit is contained in:
Hazork 2021-09-11 13:03:41 -03:00
parent 0d4854db83
commit aa83c24e18
2 changed files with 18 additions and 6 deletions

View File

@ -67,7 +67,7 @@ import { createCache, SessionCacheStorage } from 'axios-cache-interceptor';
const api = axios.create(); const api = axios.create();
// Other axios instance with caching enabled // Other axios instance with caching enabled
const cache = createCache(api, { const cachedApi = createCache(api, {
// Store values on window.sessionStorage // Store values on window.sessionStorage
storage: new SessionCacheStorage(), storage: new SessionCacheStorage(),
@ -75,8 +75,14 @@ const cache = createCache(api, {
interpretHeader: true interpretHeader: true
}); });
// Exactly the same as before // Make a requests that's only cached if the response comes with success header
cache.get('http://example.com/'); cachedApi.get('http://example.com/', {
cache: {
cachePredicate: {
containsHeaders: ['success']
}
}
});
``` ```
<br /> <br />

View File

@ -7,7 +7,7 @@ import { createCache, SessionCacheStorage } from '../src/index';
const api = axios.create(); const api = axios.create();
// Other axios instance with caching enabled // Other axios instance with caching enabled
const cache = createCache(api, { const cachedApi = createCache(api, {
// Store values on window.sessionStorage // Store values on window.sessionStorage
storage: new SessionCacheStorage(), storage: new SessionCacheStorage(),
@ -15,5 +15,11 @@ const cache = createCache(api, {
interpretHeader: true interpretHeader: true
}); });
// Exactly the same as before // Make a requests that's only cached if the response comes with success header
cache.get('http://example.com/'); cachedApi.get('http://example.com/', {
cache: {
cachePredicate: {
containsHeaders: ['success']
}
}
});