Registry / storage / axios-cache-adapter

axios-cache-adapter

JSON →
library2.7.3jsnpmunverified

Caching adapter for axios that stores GET request results in a configurable store to prevent unnecessary network requests. Current stable version is 2.7.3, with releases following a maintenance cadence. The library provides two main APIs: setupCache() for creating a standalone cache adapter, and setup() for creating a pre-configured axios instance. It supports per-request cache configuration and uses localForage as the default store. Unlike other axios caching solutions, it relies on localForage for cross-browser IndexedDB/WebSQL/LocalStorage support. Requires peer dependency axios ~0.21.1.

npm install axios-cache-adapter
INSTALL
IMPORT
SIG · AXIOS-CACHE-ADAPTE
A
axios-cache-adapter
storagejavascriptv2.7.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

setupCache
import { setupCache } from 'axios-cache-adapter'
const setupCache = require('axios-cache-adapter').setupCache
ES module import. CommonJS require is also supported.
setup
import { setup } from 'axios-cache-adapter'
import axiosCache from 'axios-cache-adapter'
setup() returns an axios instance with cache pre-configured. Default import does not exist.
default
import axiosCache from 'axios-cache-adapter'
import { default } from 'axios-cache-adapter'
Default export is an object with setup and setupCache methods. In CommonJS: const axiosCache = require('axios-cache-adapter')

Setup a cache adapter with 15-minute cache lifetime and use it with a fresh axios instance.

import axios from 'axios' import { setupCache } from 'axios-cache-adapter' const cache = setupCache({ maxAge: 15 * 60 * 1000 }) const api = axios.create({ adapter: cache.adapter }) api.get('https://httpbin.org/get').then(response => { console.log('Response:', response.data) })
Debug
Known issues
breakingVersion 2.0 changed the API: setupCache() no longer returns an axios instance itself. Must use cache.adapter.
fix
Use cache.adapter as shown in the quickstart
affects: >=2.0.0
deprecatedMethod invalidateCache() is deprecated in favor of clearing the store directly.
fix
Use cache.store.clear() or cache.store.removeItem(key)
affects: >=2.0.0
gotchaOnly GET requests are cached by default. Other methods (POST, PUT, etc.) invalidate the cache for that URL.
fix
Add methods to exclude.methods or set exclude.methods: ['post','put','delete']
affects: >=1.0.0
breakingThe peer dependency axios was updated to ~0.21.1 in version 2.5.0. Older axios versions may break.
fix
Install axios@0.21.1 or later
affects: >=2.5.0
gotchaCache keys ignore query parameters by default. Two URLs differing only by query string will be treated as the same cache key.
fix
Set exclude.query: false in cache options to include query parameters in cache key
affects: >=1.0.0
gotchaThe default store is localForage, which in private browsing mode may fallback to localStorage with limited size.
fix
Set store: null to use an in-memory store instead, or configure a custom store
affects: >=1.0.0
Errors
Common errors & fixes
Cannot read property 'adapter' of undefined
Importing setup incorrectly, e.g., default import then calling it.
fix
Use named import: import { setupCache } from 'axios-cache-adapter'
TypeError: adapter is not a function
Passing cache.adapter incorrectly, or using outdated axios version.
fix
Ensure axios version is ~0.21.1 and do: axios.create({ adapter: cache.adapter })
ReferenceError: localforage is not defined
localForage not installed or bundled, but cache store requires it.
fix
Install localforage: npm install localforage, or configure a custom store
TypeError: Cannot read properties of undefined (reading 'length')
Trying to read api.cache.length without using setup() method.
fix
Use setup() like: const api = setup({...}). Then api.cache.length works.
Upgrade
Version history
2.7.3latest on npm
Audit
Dependencies
axiosrequiredPeer dependency: adapter must be used with axios instance
Agent activity
33 hits · last 30 days
node
30
Resources
axios-cache-adapter — npm install axios-cache-adapter · libregistry