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

@pingpong-js/plugin-cache

v1.0.1

Published

Smart caching plugin for @pingpong-js/fetch with memory, localStorage, and IndexedDB support

Readme

@pingpong-js/plugin-cache

Smart caching plugin for @pingpong-js/fetch with multiple storage backends.

Installation

npm install @pingpong-js/plugin-cache
# peer dependency
npm install @pingpong-js/fetch

Features

  • 🗄️ Multiple Storage Backends: Memory, localStorage, IndexedDB
  • Configurable TTL: Time-to-live for cache entries
  • 🎯 URL Pattern Matching: Include/exclude specific URLs
  • 🔄 Stale-While-Revalidate: Serve stale data while refreshing
  • 📊 Cache Statistics: Track hits, misses, and hit rate
  • 🚫 Request Deduplication: Prevent duplicate concurrent requests

Usage

Basic Usage

import pingpong from '@pingpong-js/fetch';
import { createCache } from '@pingpong-js/plugin-cache';

const cache = createCache({
  storage: 'memory',
  ttl: 60000, // 1 minute
});

// Register cache listeners
pingpong.onRequest(cache.request);
pingpong.onResponse(cache.response);

// First request - cache miss
await pingpong.get('/api/users'); // 200ms

// Second request - cache hit
await pingpong.get('/api/users'); // <1ms

Quick Setup

import pingpong from '@pingpong-js/fetch';
import { withCachePlugin } from '@pingpong-js/plugin-cache';

const { request, response, cache } = withCachePlugin({ ttl: 60000 });

pingpong.onRequest(request);
pingpong.onResponse(response);

// Invalidate cache manually
cache.invalidate('/api/users');
cache.clear();

Storage Options

// Memory cache (default)
const memoryCache = createCache({ storage: 'memory' });

// localStorage (persists across sessions)
const localCache = createCache({ storage: 'localStorage' });

// IndexedDB (large data, persists)
const idbCache = createCache({ storage: 'indexeddb' });

Advanced Options

const cache = createCache({
  storage: 'memory',
  ttl: 5 * 60 * 1000, // 5 minutes
  maxEntries: 100,
  methods: ['GET'], // Only cache GET requests
  include: [/\/api\/users/], // Only cache matching URLs
  exclude: [/\/api\/auth/], // Exclude from caching
  staleWhileRevalidate: true, // Serve stale while refreshing
  respectCacheControl: true, // Honor server Cache-Control headers
});

Request Deduplication

Prevent duplicate concurrent requests:

import pingpong from '@pingpong-js/fetch';
import { withDedupe } from '@pingpong-js/plugin-cache';

pingpong.onRequest(withDedupe());

// These will only make ONE actual request
const [user1, user2, user3] = await Promise.all([
  pingpong.get('/api/users/1'),
  pingpong.get('/api/users/1'),
  pingpong.get('/api/users/1'),
]);

Cache Statistics

const cache = createCache();

// ... make some requests ...

console.log(cache.getStats());
// { hits: 42, misses: 10, size: 52, entries: 25 }

console.log(cache.getHitRate());
// 0.807 (80.7% hit rate)

API Reference

createCache(options?)

Creates a new cache instance.

Options:

  • storage: 'memory' | 'localStorage' | 'indexeddb' (default: 'memory')
  • ttl: Time to live in ms (default: 300000 - 5 minutes)
  • maxEntries: Maximum cache entries (default: 100)
  • methods: HTTP methods to cache (default: ['GET'])
  • include: URL patterns to cache (RegExp[])
  • exclude: URL patterns to exclude (RegExp[])
  • staleWhileRevalidate: Serve stale while refreshing (default: false)
  • respectCacheControl: Honor server Cache-Control headers (default: false)

withCachePlugin(options?)

Quick setup helper that returns request/response listeners and cache instance.

withDedupe(options?)

Request deduplication listener.

License

MIT