Skip to content

Commit

Permalink
docs: updated readme example
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Sep 11, 2021
1 parent 0d4854d commit aa83c24
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,22 @@ import { createCache, SessionCacheStorage } from 'axios-cache-interceptor';
const api = axios.create();

// Other axios instance with caching enabled
const cache = createCache(api, {
const cachedApi = createCache(api, {
// Store values on window.sessionStorage
storage: new SessionCacheStorage(),

// Use the max-age header to determine the cache expiration time
interpretHeader: true
});

// Exactly the same as before
cache.get('http://example.com/');
// Make a requests that's only cached if the response comes with success header
cachedApi.get('http://example.com/', {
cache: {
cachePredicate: {
containsHeaders: ['success']
}
}
});
```

<br />
Expand Down
12 changes: 9 additions & 3 deletions docs/readme.ts → docs/readme-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ import { createCache, SessionCacheStorage } from '../src/index';
const api = axios.create();

// Other axios instance with caching enabled
const cache = createCache(api, {
const cachedApi = createCache(api, {
// Store values on window.sessionStorage
storage: new SessionCacheStorage(),

// Use the max-age header to determine the cache expiration time
interpretHeader: true
});

// Exactly the same as before
cache.get('http://example.com/');
// Make a requests that's only cached if the response comes with success header
cachedApi.get('http://example.com/', {
cache: {
cachePredicate: {
containsHeaders: ['success']
}
}
});

0 comments on commit aa83c24

Please sign in to comment.