Catalog npm
PACKAGE EXPLORERView in registry

@021.is/spine-cache

npm

Cache helpers with TTL + tag invalidation. Wraps Next.js `unstable_cache` and `cache()` patterns; in-memory store for non-Next runtimes.

Versions collected2
Direct dependencies0From release 0.4.3
Last observed20 Oct, 22:00 UTC

README

Current package documentation

@021.is/spine-cache

TTL + tag-invalidation cache with single-flight dedupe. Fixes the classic N+1: 10 components asking for the same user concurrently → 1 backend call.

Use

import { makeMemoryCache, makeKey } from "@021.is/spine-cache";

const cache = makeMemoryCache();

async function getUser(id: string) {
  return cache.fetch(
    makeKey("user", id),
    async () => db.user.findUniqueOrThrow({ where: { id } }),
    { ttlMs: 60_000, tags: ["user", `user:${id}`] },
  );
}

// Invalidate by key or by tag
cache.invalidate(makeKey("user", id));
cache.invalidateTag("user"); // wipes ALL user entries

Why single-flight matters

Without dedupe: 10 concurrent components each call getUser("u_1") → 10 DB hits. With dedupe: 1 promise shared → 1 DB hit.

Helpers

  • makeKey("user", id, "lang", "en") → "user:u_1:lang:en" (readable in dashboards)
  • cache.size() for observability
  • cache.clear() for tests

Why not Next.js unstable_cache directly

You can combine them — unstable_cache for cross-request, spine-cache for in-request dedupe. spine-cache is process-local (no Redis), zero deps.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 2

Collected releases
VersionPublishedDirect dependenciesOpen version
0.4.3Registry latest28 May 20260
0.4.028 May 20260

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
021is/spine-ts

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:00 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:740a267c7fc331e413fd9cead0f741326636cb9be5b2678b9d9c3bbdc37166a9