JSPM

nx-cache

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 30
  • Score
    100M100P100Q63412F
  • License ISC

Minimal in-memory cache SDK for Node.js

Package Exports

  • nx-cache
  • nx-cache/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nx-cache) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

nx-cache

Minimal in-memory cache SDK for Node.js.

No setup. No config. Just use it.


Install

npm i nx-cache

Usage

import { createNxCache } from "nx-cache";

const cache = createNxCache();

Write

cache.write(
  "policy",
  { allow: true },
  {
    scope: { orgId: "acme", env: "prod" },
    metadata: { source: "api" },
  }
);
  • Same key + different scope = different entry
  • Scope can be null

Read

const res = cache.read("policy", { orgId: "acme", env: "prod" });

if (res.found) {
  console.log(res.value);
  console.log(res.metadata);
  console.log(res.meta.savedAt);
}

Without scope:

cache.read("policy"); // equivalent to scope = null

const results = cache.search("policy", { orgId: "acme", env: "prod" });

for (const r of results) {
  console.log(r.value, r.metadata);
}

Reset

cache.resetKey("policy", { orgId: "acme", env: "prod" });
cache.resetAll();

Behavior summary

  • Default TTL: 1 year
  • Expired entries are treated as not found
  • Metadata is user-defined and returned on read/search
  • Cache is per-process (memory only)

Future extensions (not in v1)

  • Redis backend
  • Disk persistence
  • Stale reads
  • Namespaced caches