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

@nifrajs/cache

v1.10.0

Published

Typed KV cache for nifra — TTL, stale-while-revalidate, tag invalidation, and single-flight stampede protection on a pluggable store (in-memory default; bring CF KV / Redis). Dependency-free, runs on Bun/Node/Deno/Workers.

Readme

@nifrajs/cache

Typed KV cache for nifra — TTL, stale-while-revalidate, tag invalidation, and single-flight stampede protection on a pluggable store (in-memory by default; bring CF KV / Redis for a shared cache). Dependency-free; runs on Bun/Node/Deno/Workers.

import { createCache } from "@nifrajs/cache"

const cache = createCache({ defaultTtlMs: 30_000 })

// Cache-aside in a loader — one DB hit per key per TTL, even under a stampede:
export async function loader({ params }) {
  const user = await cache.wrap(
    `user:${params.id}`,
    () => db.users.find(params.id),
    { ttlMs: 30_000, swrMs: 60_000, tags: [`user:${params.id}`] },
  )
  return { user }
}

// On write, drop everything tagged for that user:
await cache.invalidateTag(`user:${id}`)

Semantics

  • wrap(key, loader, opts) — returns the cached value, or runs loader, stores, and returns it.
    • Fresh (now < staleAt): the cached value, no loader call.
    • Stale-but-live (staleAt ≤ now < expiresAt, i.e. within swrMs): the stale value is returned immediately while a background refresh runs (deduped). Latency stays flat; data self-heals.
    • Miss/expired: awaits loader. Concurrent misses for the same key share one call (no stampede).
    • A throwing loader is not cached (and in the background path goes to onError, never rejects the caller).
  • set / get / has / delete, invalidateTag(tag), clear().
  • TTL: ttlMs (→ stale) + optional swrMs (→ served-stale window) + optional tags.

Stores

The default MemoryCache is in-process with lazy expiry, a tag index, and an optional LRU cap (new MemoryCache({ maxEntries: 10_000 })). For a cache shared across instances, implement CacheStore (get / set / delete / invalidateTag / clear) over CF KV, Redis, etc.:

const cache = createCache({ store: new RedisCacheStore(redis) })

On Cloudflare Workers the in-memory cache is per-isolate and short-lived — back it with CF KV (or the Cache API) via a CacheStore for anything that should survive across requests/instances.

API

  • createCache(options?)Cache{ store?, defaultTtlMs?, now?, onError? }.
  • cache.wrap(key, loader, { ttlMs?, swrMs?, tags? }) · get · has · set · delete · invalidateTag · clear.
  • MemoryCache({ maxEntries?, now? }) — the default store; implement CacheStore for your own.