nx-cache
v1.0.2
Published
Minimal in-memory cache SDK for Node.js
Maintainers
Readme
nx-cache
Minimal in-memory cache SDK for Node.js.
No setup. No config. Just use it.
Install
npm i nx-cacheUsage
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 = nullSearch
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
