npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ben-bradley/c-cache-lru

v0.1.0

Published

LRU storage adapter for c-cache (wraps lru-cache, implements CacheStorage)

Readme

@ben-bradley/c-cache-lru

LRU storage adapter for c-cache.

Wraps the popular lru-cache package and implements the CacheStorage contract so it can be passed to createCache({ storage }).

Core c-cache stays dependency-free. This package is optional and pulls in lru-cache only when you need a full-featured LRU (size limits, disposal hooks, maxSize, autopurge, etc.) beyond the lightweight MapStorage that ships with the core.

Install

npm install @ben-bradley/c-cache @ben-bradley/c-cache-lru

Quick start

import cluster from 'node:cluster';
import { availableParallelism } from 'node:os';
import { createCache } from '@ben-bradley/c-cache';
import { LruStorage } from '@ben-bradley/c-cache-lru';

const cache = createCache({
  storage: new LruStorage({
    max: 10_000,
    ttl: 5 * 60_000, // 5 minutes
    updateAgeOnGet: true,
  }),
});

if (cluster.isPrimary) {
  const n = availableParallelism();
  for (let i = 0; i < n; i++) cluster.fork();
} else {
  await cache.set('user:42', { name: 'Ada' });
  console.log(await cache.get('user:42')); // visible to every worker
}

Call createCache() in both the primary and workers (same rule as core c-cache). The primary owns the LruStorage instance; workers talk over cluster IPC.

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | max | number | — | Max entries; LRU eviction when full | | ttl | number | — | TTL in ms; expired entries treated as miss | | updateAgeOnGet | boolean | false | Refresh TTL on successful get | | allowStale | boolean | false | Return expired value once on get | | maxSize | number | — | Max total size (requires sizeCalculation) | | sizeCalculation | (value, key) => number | — | Per-item size for maxSize | | dispose | (value, key, reason) => void | — | Called on eviction / delete | | updateAgeOnHas | boolean | false | Refresh TTL on has | | ttlAutopurge | boolean | false | Proactively purge expired items |

At least one of max, ttl, or maxSize is required. Option validation is deferred to lru-cache (invalid values throw from its constructor).

const storage = new LruStorage({
  max: 5000,
  ttl: 60_000,
  dispose: (value, key) => {
    // e.g. close a handle, free external resources
  },
});

Why a separate package?

  • Core c-cache has zero runtime dependencies.
  • Many users only need the simple MapStorage (already LRU-ish via Map insertion order).
  • Users who need the full lru-cache feature set (size accounting, dispose, iterators, dump/load, etc.) opt in to this adapter.

API

import { LruStorage } from '@ben-bradley/c-cache-lru';
import type { LruStorageOptions } from '@ben-bradley/c-cache-lru';

const storage = new LruStorage<K, V>(options?: LruStorageOptions<K, V>);

storage.get(key);    // V | undefined
storage.set(key, value);
storage.delete(key); // boolean
storage.has(key);    // boolean
storage.clear();

storage.size;        // number (extra, not on CacheStorage)
storage.underlying;  // the raw LRUCache instance

Example

See examples/basic-cluster.mjs for a runnable multi-process demo (same shape as core c-cache's cluster example, using LruStorage as the backend).

npm run build
node examples/basic-cluster.mjs

Development

npm install
npm run build
npm test

License

MIT