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

lru-stampede-guard

v1.0.2

Published

A lightweight async deduplication cache to prevent cache stampedes. Built on tiny-lru.

Readme

lru-stampede-guard

A high-performance, lightweight async deduplication cache for Node.js.

lru-stampede-guard prevents cache stampedes (also known as dog-piling). When multiple concurrent requests ask for the same resource, the expensive factory function (database query, API call, etc.) is executed only once. All other callers await the same in-flight promise.

Built on top of the extremely fast and minimal tiny-lru.


Features

  • Lightweight – Minimal overhead, powered by tiny-lru
  • Stampede Protection – Deduplicates concurrent async requests
  • Self-Healing – Failed promises are automatically evicted so retries work
  • TypeScript First – Written in TypeScript with full type definitions

Installation

npm install lru-stampede-guard

Usage

CommonJS (Node.js)

const { StampedeGuard } = require("lru-stampede-guard");

// Initialize the cache
const cache = new StampedeGuard({
  max: 1000, // Maximum items in memory
  ttl: 60000, // Time-to-live: 60 seconds (ms)
});

// Mock database function
const getUserFromDb = async (id) => {
  console.log("⚡ DB Query Executed");
  return { id, name: "Alice" };
};

async function handler(userId) {
  // fetch(key, factoryFn)
  // If 50 requests hit this at once, the DB query runs ONLY ONCE
  const user = await cache.fetch(`user:${userId}`, () => getUserFromDb(userId));

  return user;
}

TypeScript

import { StampedeGuard } from "lru-stampede-guard";

interface User {
  id: number;
  name: string;
}

const cache = new StampedeGuard({
  max: 500,
  ttl: 10000,
});

async function getUser(id: number): Promise<User> {
  // Pass a generic to fetch<T>() for strict typing
  return cache.fetch<User>(`user:${id}`, async () => {
    return await db.query<User>("SELECT * FROM users WHERE id = ?", [id]);
  });
}

API Reference

new StampedeGuard(options?)

Creates a new cache instance.

Options

  • options.max (number) Maximum number of items in the cache Default: 1000

  • options.ttl (number) Time-to-live in milliseconds Default: 0 (never expires)

fetch(key, factoryFn, ttl?)

Returns the cached value if it exists. If the value is missing, the factoryFn is executed and its promise is cached. Concurrent calls for the same key will await the same promise.

Parameters

  • key (string) Unique cache key

  • factoryFn (function) Async function that returns the value

  • ttl (number, optional) Overrides the default TTL for this entry

Returns

  • Promise<T>

delete(key)

Manually removes a single item from the cache.

cache.delete("user:123");

clear()

Clears all items from the cache.

cache.clear();

Why Use This?

The Problem (Without This Library)

If your server takes 500ms to fetch a user profile and 100 requests arrive within that window, your backend will trigger 100 identical database queries.

This causes:

  • Unnecessary load
  • CPU spikes
  • Database exhaustion
  • Increased latency

The Solution (With lru-stampede-guard)

  • The first request triggers the database query
  • The next 99 requests detect an in-flight promise
  • All requests await the same result
  • The database is hit once

Result: faster responses, lower load

License

MIT