Registry / testing / axios-cache-plugin

axios-cache-plugin

JSON →
library0.1.0jsnpmunverified

A lightweight plugin that adds client-side caching for GET requests made with Axios. It wraps an Axios instance or the default Axios, caching responses in memory based on URL and optional headers. Version 0.1.0 (latest as of March 2025) is a stable release with minimal updates. Key features: configurable max cache size (default 15), TTL support, and exclusion of headers from cache keys. Unlike more comprehensive caching libraries (e.g., axios-extensions), this plugin uses explicit filter registration via regex patterns, giving precise control over which requests are cached. It is simple and focused, suitable for small to medium projects.

npm install axios-cache-plugin
INSTALL
IMPORT
SIG · AXIOS-CACHE-PLUGIN
A
axios-cache-plugin
testingjavascriptv0.1.0
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.

wrapper
import wrapper from 'axios-cache-plugin'
const { wrapper } = require('axios-cache-plugin')
Package uses CommonJS exports; default import is the wrapper function.
wrapper (default import)
const wrapper = require('axios-cache-plugin').default
const wrapper = require('axios-cache-plugin')
In CommonJS, require('axios-cache-plugin') returns module.exports, which has no default property. Use .default to get the wrapper function.
__addFilter
import wrapper from 'axios-cache-plugin'; const http = wrapper(axios); http.__addFilter(/pattern/)
axios.__addFilter(/pattern/)
__addFilter is a method on the wrapped instance, not on the original axios.
__clearCache
http.__clearCache()
axios.__clearCache()
Cache methods are only available on the proxy returned by wrapper(), not on the original axios instance.

Demonstrates basic setup: wrapping axios, adding a regex filter, making a cached GET request, and clearing the cache.

import axios from 'axios'; import wrapper from 'axios-cache-plugin'; // Create wrapped instance with options const http = wrapper(axios, { maxCacheSize: 20, ttl: 60000, excludeHeaders: true }); // Add filter: only cache URLs matching this regex http.__addFilter(/\/api\//); // This GET request will be cached http.get('https://api.example.com/data') .then(response => console.log(response.data)) .catch(err => console.error(err)); // Clear all cached entries http.__clearCache();
Debug
Known issues
gotchaCache is never used unless a filter is added via __addFilter(). Without a filter, all GET requests bypass cache.
fix
Always call http.__addFilter(/regex/) with a pattern that matches the URLs you want to cache.
affects: *
gotchaIncluding default headers (like Authorization) in the request may cause cache misses unless excludeHeaders is set to true.
fix
Set excludeHeaders: true in wrapper options to ignore headers when generating cache keys.
affects: <0.1.0
gotchaOnly GET requests are cached. POST, PUT, DELETE, etc. are never cached regardless of filters.
fix
Use only for caching GET requests. For other methods, implement a custom caching solution.
affects: *
deprecatedPackage has not been updated in several years. There is no support for Axios v1.x or newer versions.
fix
Consider migrating to axios-extensions or implementing a custom Axios adapter for caching.
affects: *
Errors
Common errors & fixes
TypeError: axios__default is not a function
Importing the default export incorrectly in CommonJS (e.g., const wrapper = require('axios-cache-plugin')). The module exports as a default property.
fix
Use const wrapper = require('axios-cache-plugin').default;
Uncaught TypeError: http.__addFilter is not a function
Calling __addFilter on the original axios instance instead of the wrapped proxy returned by wrapper().
fix
Ensure you call __addFilter on the object returned by wrapper(axios, options).
Request not being cached even after adding filter
The request method is not GET, or the URL does not match the filter regex, or headers are causing cache key mismatch.
fix
Verify the request is GET, the URL matches the filter, and set excludeHeaders: true to ignore header variations.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies
axiosrequiredpeer dependency; the plugin wraps Axios instances
Agent activity
23 hits · last 30 days
node
20
OpenAI (training)
1
Resources
axios-cache-plugin — npm install axios-cache-plugin · libregistry