npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

quick-axios-cache

v1.0.0

Published

A simple, lightweight, and customisable in-memory cache for Axios requests with TTL.

Readme

quick-axios-cache

A simple, lightweight, and customisable in-memory cache for Axios requests with Time-To-Live (TTL) support.

Features

  • 🚀 Transparent Caching — wraps any Axios instance, requiring no changes to your existing request calls.
  • ⏱️ TTL Support — configures how long cached items are valid.
  • 🛠️ Custom Key Building — customisable key generation based on method, URL, params, or request data.
  • 📦 Control Interface — clear the cache, inspect the cache size, or delete specific keys on demand.
  • 🛡️ Safe Copying — returns clones of cached responses to prevent mutation side-effects.

Installation

npm install quick-axios-cache

Note: axios is required as a peer dependency.

Usage

const axios = require('axios');
const { setupCache } = require('quick-axios-cache');

// Create an Axios instance
const api = axios.create({
  baseURL: 'https://jsonplaceholder.typicode.com'
});

// Enable caching (with 10-second TTL)
const cacheController = setupCache(api, {
  ttl: 10000, // 10 seconds in ms
  onCacheHit: (key) => console.log(`[Cache Hit] Key: ${key}`),
  onCacheMiss: (key) => console.log(`[Cache Miss] Key: ${key}`)
});

async function run() {
  // First call -> Cache Miss (fetches from network)
  const res1 = await api.get('/todos/1');
  console.log('Fetched Todo 1:', res1.data.title);

  // Second call within 10s -> Cache Hit (returns from memory)
  const res2 = await api.get('/todos/1');
  console.log('Fetched Todo 1 (Cached):', res2.data.title);
  console.log('Is Cached:', res2.headers['x-axios-cache'] === 'HIT'); // true

  // Inspect or clear cache
  console.log('Cache Size:', cacheController.size); // 1
  cacheController.clear();
  console.log('Cache Size after clear:', cacheController.size); // 0
}

run();

Options

setupCache(axiosInstance, options) accepts the following options:

| Option | Type | Default | Description | |---|---|---|---| | ttl | number | 60000 | Time-to-Live in milliseconds. | | methods | Array<string> | ['get'] | HTTP methods to cache (must be lowercase). | | buildCacheKey | Function | Default Key Builder | A function (config) => string that returns a unique cache key based on the request config. | | onCacheHit | Function | () => {} | Callback invoked on cache hit. | | onCacheMiss | Function | () => {} | Callback invoked on cache miss. |

Controller API

setupCache returns a controller object:

const cacheController = setupCache(api);

cacheController.clear();       // Clears the entire cache
cacheController.delete(key);   // Deletes a specific cache key
cacheController.getCache();    // Returns the internal Map instance
console.log(cacheController.size); // Get total cached items count

License

MIT