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

@disckit/cache

v1.3.0

Published

LRU and TTL cache implementations. Doubly-linked-list + Map for O(1) get/set.

Readme


Features

  • LRUCache — pure LRU eviction, O(1) get/set/delete via doubly-linked-list + Map
  • TTLCache — LRUCache + per-entry expiration with lazy eviction on access
  • createCache() — factory helper for the most common case
  • peek() — read without updating recency position
  • purgeExpired() — proactively evict expired entries
  • Full TypeScript generics — LRUCache<K, V> · Zero dependencies · Node.js 18+

For async loading, background refresh and request coalescing, see @disckit/caffeine.

Installation

npm install @disckit/cache
yarn add @disckit/cache
pnpm add @disckit/cache

TypeScript / ESM

Types are bundled — no extra install needed.
Supports both CommonJS and ESM:

// ESM
import { LRUCache, TTLCache, createCache } from '@disckit/cache';

// CommonJS
const { LRUCache, TTLCache, createCache } = require('@disckit/cache');

Usage

LRUCache — pure LRU, no expiration

const { LRUCache } = require('@disckit/cache');

const cache = new LRUCache(500); // max 500 entries

cache.set('guild:123', { prefix: '!', lang: 'pt' });
cache.get('guild:123'); // → { prefix: '!', lang: 'pt' }  (promotes to MRU)
cache.peek('guild:123'); // → same value, does NOT update recency
cache.has('guild:123'); // → true
cache.delete('guild:123');
cache.size; // → current entry count

When the cache reaches capacity, the least recently used entry is evicted automatically.

TTLCache — LRU + expiration

const { TTLCache } = require('@disckit/cache');

// Default TTL of 5 minutes for all entries
const cache = new TTLCache(200, 5 * 60 * 1000);

cache.set('user:456', userData);
cache.set('user:789', tempData, 30_000); // override: this entry expires in 30s

cache.get('user:456');    // → userData (if not expired)
cache.has('user:456');    // → true (checks expiry)

// Proactively remove expired entries (cache evicts lazily by default)
cache.purgeExpired();

// Iterate only live entries
for (const [key, value] of cache.entries()) {
  console.log(key, value); // expired entries are skipped
}

createCache() — factory shortcut

const { createCache } = require('@disckit/cache');

const lru = createCache(100);          // LRUCache, no expiration
const ttl = createCache(100, 60_000);  // TTLCache, 1 min TTL

Real-world example — invite cache for a Discord bot

const { TTLCache } = require('@disckit/cache');

// Cache invite codes per guild for 10 minutes
const inviteCache = new TTLCache(500, 10 * 60 * 1000);

client.on('guildMemberAdd', async member => {
  const cached = inviteCache.get(member.guild.id);
  if (!cached) {
    const invites = await member.guild.invites.fetch();
    inviteCache.set(member.guild.id, invites);
  }
  // compare cached vs current to detect which invite was used
});

API Reference

LRUCache<K, V>

| Method | Returns | Description | |--------|---------|-------------| | get(key) | V \| undefined | Get value and promote to MRU | | peek(key) | V \| undefined | Get value without updating recency | | set(key, value) | void | Set value, evicting LRU if at capacity | | has(key) | boolean | Check if key exists | | delete(key) | boolean | Remove key | | clear() | void | Remove all entries | | entries() | IterableIterator | LRU → MRU pairs | | keys() | K[] | All keys LRU → MRU | | size | number | Current entry count |

TTLCache<K, V> — same as LRUCache plus:

| Method | Returns | Description | |--------|---------|-------------| | set(key, value, ttlMs?) | void | Optional per-entry TTL override | | purgeExpired() | number | Evict all expired entries, returns count | | entries() | Array<[K, V]> | Live entries only (expired skipped) |

Links