Skip to content

Getting started ​

Looking for axios v0?

Install ​

Install Axios and Axios Cache Interceptor:

bash
npm install axios@^1 axios-cache-interceptor@^1
html
<!-- 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>
ts
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:

ts
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; // true
ts
const 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; // true
ts
const 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; // true
ts
import 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; // true

setupCache(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)

AxiosAxios 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:

bash
npx skills add arthurfiorette/axios-cache-interceptor

This uses the Skills CLI. Once installed, your assistant can read the library’s API reference and common usage patterns.

Read more ​

Made with ❤️