Getting started
Install
Install Axios and Axios Cache Interceptor:
npm install axios@^1 axios-cache-interceptor@^1<!-- Development UMD build (~22 KiB) -->
<script src="https://cdn.jsdelivr.net/npm/axios-cache-interceptor@1/dev/index.bundle.js"></script>
<!-- Production UMD build (~18 KiB) -->
<script src="https://cdn.jsdelivr.net/npm/axios-cache-interceptor@1/dist/index.bundle.js"></script>import Axios from 'https://cdn.skypack.dev/axios';
import { setupCache } from 'https://cdn.skypack.dev/axios-cache-interceptor';Setup
Import setupCache and apply it to your axios instance:
import Axios from 'axios';
import { setupCache } from 'axios-cache-interceptor';
const instance = Axios.create();
const axios = setupCache(instance);
const req1 = axios.get('https://api.example.com/');
const req2 = axios.get('https://api.example.com/');
const [res1, res2] = await Promise.all([req1, req2]);
res1.cached; // false
res2.cached; // trueconst Axios = require('axios');
const { setupCache } = require('axios-cache-interceptor');
const instance = Axios.create();
const axios = setupCache(instance);
const req1 = axios.get('https://api.example.com/');
const req2 = axios.get('https://api.example.com/');
const [res1, res2] = await Promise.all([req1, req2]);
res1.cached; // false
res2.cached; // trueconst Axios = window.axios;
const { setupCache } = window.AxiosCacheInterceptor;
const instance = Axios.create();
const axios = setupCache(instance);
const req1 = axios.get('https://api.example.com/');
const req2 = axios.get('https://api.example.com/');
const [res1, res2] = await Promise.all([req1, req2]);
res1.cached; // false
res2.cached; // trueimport Axios from 'https://cdn.skypack.dev/axios';
import { setupCache } from 'https://cdn.skypack.dev/axios-cache-interceptor';
const instance = Axios.create();
const axios = setupCache(instance);
const req1 = axios.get('https://api.example.com/');
const req2 = axios.get('https://api.example.com/');
const [res1, res2] = await Promise.all([req1, req2]);
res1.cached; // false
res2.cached; // truesetupCache(instance) registers both cache interceptors. If you need a custom interceptor order, see Other interceptors.
This is enough for most use cases. To change the defaults, pass a configuration object to setupCache. To change the behavior of a single request, use the cache option in its request config.
Support table
Most breaking changes in Axios v0 were typing issues, so your version may work with a combination outside this table. Axios and Axios Cache Interceptor v0 are not compatible with Axios and Axios Cache Interceptor v1.
Note: Not every v0 release declared Axios as a
peerDependency, because Axios did not follow stable semver at the time. See #145 (Comment)
| Axios | Axios Cache Interceptor |
|---|---|
>= v1.7.8 | >= v1.7.0 |
>= v1.6 | >= v1.3.0 && <= 1.6.2 |
>= v1.4 | >= v1.2.0 |
>= v1.3.1 | >= v1 |
>= v0.27 | >= v0.10.3 |
>= v0.26 | >= v0.8.4 |
~ v0.25 | ~ v0.8.4 |
~ v0.24 | >= v0.5 && <= 0.8.3 |
~ v0.23 | ~ v0.4 |
~ v0.22 | ~ v0.3 |
v0.21 | <= v0.2 |
AI / LLM skill
If you use an AI coding assistant, install the axios-cache-interceptor skill to give it up-to-date context about this library:
npx skills add arthurfiorette/axios-cache-interceptorThis uses the Skills CLI. Once installed, your assistant can read the library’s API reference and common usage patterns.
