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

@ghost_debugger/nanocache

v0.1.0

Published

Tiny isomorphic async memoize + cache: in-flight dedupe, stale-while-revalidate, TTL and LRU. Zero dependencies. Runs on the browser, Node, Deno, Bun and edge.

Readme

nanocache

Tiny isomorphic async memoize + cache. In-flight dedupe, stale-while-revalidate, TTL and LRU. Zero dependencies.

One cache primitive for your whole stack — the same code runs in the browser, Node, Deno, Bun, and edge/serverless. No window, no process, no build-target juggling.

  • 🧬 Isomorphic — universal JS only (Map, Promise, Date.now). Nothing environment-specific.
  • 🚦 In-flight dedupe — concurrent calls with the same key share a single execution (kills thundering-herd / duplicate requests).
  • 🔄 Stale-while-revalidate — serve the cached value instantly, refresh in the background.
  • ⏱️ TTL + LRU — bound entries by age (maxAge) and count (maxSize) so long-running processes don't leak memory.
  • 🛡️ Never poisons the cache — rejected promises are not cached.
  • 🎛️ Full controlget / set / has / delete / clear / keyOf on the memoized function.
  • 📦 ~1 KB, zero deps, dual ESM + CJS, fully typed.

Install

npm install nanocache

Quick start

import { memoize } from "nanocache";

const getUser = memoize(
  async (id: string) => {
    const res = await fetch(`/api/users/${id}`);
    return res.json();
  },
  {
    maxAge: 60_000,             // cache for 60s
    staleWhileRevalidate: true, // serve stale instantly, refresh in background
    maxSize: 1000,              // keep at most 1000 users in memory
  },
);

await getUser("1"); // miss → fetches
await getUser("1"); // hit → cached

// 50 concurrent calls, ONE network request:
await Promise.all(Array.from({ length: 50 }, () => getUser("1")));

Works with sync functions too — you just get TTL/LRU caching (the async-only features engage automatically when the wrapped function returns a promise):

const fib = memoize((n: number): number => (n < 2 ? n : fib(n - 1) + fib(n - 2)));

API

memoize(fn, options?)

Returns a memoized version of fn with cache-control methods attached.

| Option | Type | Default | Description | | --- | --- | --- | --- | | maxAge | number | Infinity | Time-to-live in ms. | | maxSize | number | Infinity | Max entries in the default LRU store. | | staleWhileRevalidate | boolean | false | Return stale value, refresh in background. | | key | (...args) => string | stable serialize | Derive the cache key from arguments. | | store | CacheStore | in-memory LRU | Swap in a custom (synchronous) store. |

Cache-control methods

getUser.keyOf("1");        // "1" — the key these args map to
getUser.has("1");          // boolean — is a fresh entry cached?
getUser.get("1");          // peek at the cached value (no call)
getUser.set("1", user);    // prime the cache
getUser.delete("1");       // evict one key
getUser.clear();           // evict everything

Default cache key

A single primitive argument is used verbatim (getUser("1") → key "1"). Otherwise arguments are serialized deterministically with sorted object keys, so { a: 1, b: 2 } and { b: 2, a: 1 } hit the same entry. For arguments that aren't JSON-representable (Map, Set, Date, BigInt, functions, circular refs), pass your own key function.

How it compares

| | nanocache | p-memoize | memoizee | lru-cache | | --- | :---: | :---: | :---: | :---: | | Isomorphic (browser + server) | ✅ | ✅ | ✅ | ✅ | | In-flight dedupe (coalescing) | ✅ | ⚠️ partial | ❌ | ❌ (not a memoizer) | | Stale-while-revalidate | ✅ | ❌ | ❌ | ❌ | | TTL | ✅ | via add-on | ✅ | ✅ | | LRU bound | ✅ | via add-on | ⚠️ | ✅ | | Doesn't cache rejections | ✅ | ✅ | ⚠️ | n/a | | Runtime dependencies | 0 | 0 | several | 0 |

Universality

The published code touches only APIs present in every JavaScript runtime, so it ships unmodified everywhere:

| Environment | Supported | | --- | :---: | | Browser (bundled) | ✅ | | Node.js (ESM + CJS) | ✅ | | Deno / Bun | ✅ | | Edge / serverless (Cloudflare, Vercel Edge) | ✅ | | React Native | ✅ |

The source is type-checked with no ambient Node or DOM globals, so any accidental use of an environment-specific API fails the build — the isomorphism guarantee is enforced, not just claimed.

Not in v1 (planned)

  • Async / remote stores (e.g. Redis) — the store interface stays synchronous for now.
  • AbortSignal cancellation.

License

MIT