Skip to content

Commit

Permalink
docs: updated minimal example
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Oct 12, 2021
1 parent 3ed92c8 commit dd1fa41
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,19 @@ Axios Cache Interceptor</h1>

```ts
import axios from 'axios';
import { createCache, SessionCacheStorage } from 'axios-cache-interceptor';
import { useCache, SessionCacheStorage } from 'axios-cache-interceptor';

// Any custom axios instance
const api = axios.create();

// Other axios instance with caching enabled
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
// An axios instance with modified types
const api = useCache(axios.create(), {
/* options */
});

// Make a simple request, with caching support, to the api
const { data } = await cachedApi.get('https://api.example.com/');
const resp1 = await api.get('https://api.example.com/');
// resp1.cached = false

const resp2 = await api.get('https://api.example.com/');
// resp2.cached = true
```

<br />
Expand Down Expand Up @@ -178,7 +175,7 @@ After that, you can made your own requests normally.

## What we support

- [x] Cache concurrent requests
- [x] Concurrent requests
- [x] Typescript support
- [x] Unit tests
- [x] Header interpretation
Expand Down

0 comments on commit dd1fa41

Please sign in to comment.