v0.2.0 ยท Node 18+ ยท prebuilt binaries

Ultra-fast in-memory cache powered by Rust

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
cache.ts
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

Why rust-node-cache

โšก

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.

๐Ÿ”’

Thread-safe

Built on DashMap, a lock-sharded concurrent map. Operations on different keys run in parallel โ€” no global lock.

โฑ๏ธ

TTL support

Per-entry expiration with ttlSeconds. Lazy eviction on access plus an active cleanupExpired() sweep.

๐Ÿ“Š

Built-in stats

Track hits, misses, sets, deletes, expired and size with atomic counters.

๐Ÿงฉ

TS-first API

Generated .d.ts, generics like get<User>(), and dual CommonJS + ESM output.

๐Ÿ”Œ

Framework ready

Drop-in response caching for Express, a Fastify plugin, and a NestJS interceptor.

Usage

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
// }

Framework integrations

Express

import { cacheMiddleware }
  from "rust-node-cache/express";

app.get("/users/:id",
  cacheMiddleware({ cache, ttlSeconds: 60 }),
  handler);

Fastify

import { cachePlugin }
  from "rust-node-cache/fastify";

fastify.register(cachePlugin,
  { cache, ttlSeconds: 60 });

NestJS

import { CacheInterceptor }
  from "rust-node-cache/nestjs";

app.useGlobalInterceptors(
  new CacheInterceptor({ cache }));

Supported platforms

macOS arm64 macOS x64 Linux x64 (glibc) Linux arm64 (glibc) Windows x64

Roadmap