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

axios-mongo-cache

v1.0.0

Published

Ultra-simple Axios caching interceptor with optional MongoDB persistence (auto-detects local Mongo on common ports).

Readme

axios-mongo-cache

npm version License: MIT

Ultra-simple Axios caching interceptor with optional MongoDB persistence. It auto-detects local MongoDB on common ports, making it a breeze to set up.

Features

  • Two-layer Cache: In-memory cache for speed, with an optional MongoDB backend for persistence.
  • Auto-detection: Automatically discovers local MongoDB instances on common ports (27017-27020).
  • Request Deduplication: Concurrent identical requests are deduplicated, with only one actual network request being made.
  • Customizable: Configure cache TTL, which HTTP methods to cache, and more.
  • Easy Setup: Integrates with Axios as an interceptor.

Installation

# Using npm
npm install axios-mongo-cache axios mongodb

# Using pnpm
pnpm add axios-mongo-cache axios mongodb

Usage

Here's a quick example of how to use axios-mongo-cache:

import axios from 'axios';
import setupAxiosMongoCache from 'axios-mongo-cache';

async function run() {
  // Create an Axios instance
  const api = axios.create();

  // Set up the cache
  const { clearCache, close } = await setupAxiosMongoCache(api, {
    dbName: 'MyCacheDB',
    collectionName: 'NetworkRequestCache',
    ttl: 1000 * 60 * 5, // 5 minutes
    useMongo: true,
    methods: ['get']
  });

  // Make a request - the first time it will hit the network
  console.log('First fetch (network expected)');
  const response1 = await api.get('https://jsonplaceholder.typicode.com/todos/1');
  console.log('Data:', response1.data);

  // Make the same request again - this time it will be served from the cache
  console.log('\nSecond fetch (should be cached)');
  const response2 = await api.get('https://jsonplaceholder.typicode.com/todos/1');
  console.log('Data:', response2.data);

  // Clean up
  await clearCache();
  await close();
}

run().catch(console.error);

The setupAxiosMongoCache function returns two helper methods:

  • clearCache(): Clears both the in-memory and MongoDB cache.
  • close(): Closes the MongoDB connection and ejects the interceptors.

Configuration

You can pass the following options to setupAxiosMongoCache:

| Option | Type | Default | Description | | ---------------- | --------- | ------------------------- | ------------------------------------------------------------------------------------------------------- | | mongoUri | string | null | Full MongoDB connection URI. If not provided, the library will attempt to auto-discover a local instance. | | dbName | string | null | The name of the database to use. Required if useMongo is true and mongoUri is not provided. | | collectionName | string | 'NetworkRequestCache' | The name of the collection to store cache data. | | ttl | number | Infinity | Time-to-live for cache entries in milliseconds. Defaults to Infinity (never expire). | | useMongo | boolean | true | Whether to use MongoDB for persistence. If false, only an in-memory cache is used. | | methods | string[]| ['get'] | An array of HTTP methods to cache (in lowercase). |

License

This project is licensed under the MIT License - see the LICENSE file for details.