Fast reads & writes
The hot path is native Rust. Values are stored as a single contiguous buffer โ minimal allocation, no GC pauses on the cache.
A thread-safe cache for Node.js with a native core built on DashMap and napi-rs. Fast reads, fast writes, TTL support and built-in stats โ through a clean TypeScript API.
npm install rust-node-cache
import { Cache } from "rust-node-cache";
const cache = new Cache();
cache.set("user:1", { id: 1, name: "Roberto" });
const user = cache.get("user:1");
// { id: 1, name: "Roberto" }
cache.set("session:123", session, { ttlSeconds: 60 });
// expires automatically after 60s
The hot path is native Rust. Values are stored as a single contiguous buffer โ minimal allocation, no GC pauses on the cache.
Built on DashMap, a lock-sharded concurrent map.
Operations on different keys run in parallel โ no global lock.
Per-entry expiration with ttlSeconds. Lazy eviction on
access plus an active cleanupExpired() sweep.
Track hits, misses, sets,
deletes, expired and size
with atomic counters.
Generated .d.ts, generics like
get<User>(), and dual CommonJS + ESM output.
Drop-in response caching for Express, a Fastify plugin, and a NestJS interceptor.
import { Cache } from "rust-node-cache";
const cache = new Cache();
cache.set("user:1", { id: 1, name: "Roberto" });
const user = cache.get<User>("user:1"); // User | null
cache.exists("user:1"); // true
cache.delete("user:1"); // true
cache.size(); // 0
import { Cache } from "rust-node-cache";
const cache = new Cache();
// Expires automatically after 60 seconds.
cache.set("session:123", session, { ttlSeconds: 60 });
cache.get("session:123"); // session ... then null once expired
// Proactively reclaim memory from stale keys.
const removed = cache.cleanupExpired();
import { Cache } from "rust-node-cache";
const cache = new Cache();
console.log(cache.stats());
// {
// hits: 1500,
// misses: 200,
// sets: 800,
// deletes: 20,
// expired: 15,
// size: 780
// }
import { cacheMiddleware }
from "rust-node-cache/express";
app.get("/users/:id",
cacheMiddleware({ cache, ttlSeconds: 60 }),
handler);
import { cachePlugin }
from "rust-node-cache/fastify";
fastify.register(cachePlugin,
{ cache, ttlSeconds: 60 });
import { CacheInterceptor }
from "rust-node-cache/nestjs";
app.useGlobalInterceptors(
new CacheInterceptor({ cache }));