Registry / devops / axios-cacher

axios-cacher

JSON →
library1.1.4jsnpmunverified

Axios-cacher is a lightweight caching wrapper for Axios that stores API response data in memory with configurable expiration (maxAge) and manual cache invalidation via user keys. The current stable version is 1.1.4, released in 2021 with no notable update cadence. It provides a setup function returning both a cached axios client and an invalidation helper. Unlike generic caching solutions, it ties cache entries to unique user keys for targeted invalidation. The package is minimal (no persistence, no external dependencies beyond axios) and targets Node.js environments.

npm install axios-cacher
INSTALL
IMPORT
SIG · AXIOS-CACHER
A
axios-cacher
devopsjavascriptv1.1.4
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.

setup
import setup from 'axios-cacher'
const { setup } = require('axios-cacher')
Default export only. CommonJS require will give an object with setup as a property (but actually default export is function). Use import or use require('axios-cacher').default.
axiosClient
const { axiosClient } = setup({...})
import { axiosClient } from 'axios-cacher'
axiosClient is returned by the setup function, not directly exported.
invalidateThis
const { invalidateThis } = setup({...})
import { invalidateThis } from 'axios-cacher'
invalidateThis is returned by the setup function.

Demonstrates setup with caching, making a cached GET request, and manually invalidating the cache entry.

import setup from 'axios-cacher'; const { axiosClient, invalidateThis } = setup({ baseURL: process.env.API_URL ?? 'https://jsonplaceholder.typicode.com', headers: { 'Content-Type': 'application/json' }, cache: { maxAge: 5 * 60 * 1000, // 5 minutes invalidate: async (config, request) => { if (request.clearCacheEntry) { await config.store.removeItem(config.uuid); } } } }); async function main() { const response = await axiosClient.get('/posts/1', { userKey: 'test' }); console.log(response.data); // Invalidate cache for userKey 'test' await invalidateThis('test'); } main();
Debug
Known issues
gotchasetup function expects cache.invalidate to be async; if not async, invalidation may fail silently.
fix
Ensure invalidate function is async or returns a promise.
affects: >=1.0.0
gotchaIn memory cache - data is not persisted across server restarts.
fix
Use a persistent cache adapter if needed (not built-in).
affects: >=1.0.0
breakingThe package has no TypeScript types; using with TypeScript requires custom type declarations.
fix
Create a .d.ts file: declare module 'axios-cacher' { function setup(config: any): { axiosClient: any; invalidateThis: (key: string) => Promise<void> }; export default setup; }
affects: >=1.0.0
gotchauserKey parameter must be passed in request config; if omitted, cache will not be properly keyed and invalidation may not work.
fix
Always include userKey in the request config object for each call you want to cache/invalidate.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot destructure property 'axiosClient' of (intermediate value)(...) as it is undefined.
setup() returned undefined because configuration object was missing required fields.
fix
Ensure setup() is called with a valid config object containing baseURL and cache.maxAge.
TypeError: (0 , _axiosCacher.default) is not a function
Using CommonJS require incorrectly - trying to call require('axios-cacher') as a function without accessing .default.
fix
Use const setup = require('axios-cacher').default; or use ES import syntax.
Request failed with status code 404
Cache returns stale 404 response because the URL was changed or API endpoint no longer exists.
fix
Invalidate cache or increase maxAge with error handling to retry fresh requests on failure.
Upgrade
Version history
1.1.4latest on npm
Audit
Dependencies
axiosrequiredPeer dependency - wraps axios instance for caching HTTP requests.
Agent activity
18 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
axios-cacher — npm install axios-cacher · libregistry