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

v1.3.0

Published

Caffeine-inspired async cache builder. expireAfterWrite, expireAfterAccess, refreshAfterWrite, request coalescing.

Readme


Features

  • Builder patternCacheBuilder.newBuilder()...buildAsync(loader)
  • expireAfterWrite — entries expire N ms after last write
  • expireAfterAccess — entries expire N ms after last read (idle timeout)
  • refreshAfterWrite — return stale value immediately, reload in background
  • onEviction — callback fired on every eviction with reason: 'size' | 'expired' | 'manual'
  • Request coalescing — concurrent get() calls for the same key → 1 loader call
  • Stats — hits, misses, loads, errors, evictions, refreshes
  • Full TypeScript types included · Zero dependencies · Node.js 18+

Inspired by the Java Caffeine library used by Loritta.

Installation

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

TypeScript / ESM

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

// ESM
import { CacheBuilder, CaffeineCache } from '@disckit/caffeine';

// CommonJS
const { CacheBuilder } = require('@disckit/caffeine');

Usage

Guild settings cache (most common use case)

const { CacheBuilder } = require('@disckit/caffeine');

const guildCache = CacheBuilder.newBuilder()
  .maximumSize(500)
  .expireAfterAccess(30 * 60 * 1000)  // evict guilds idle for 30 min
  .refreshAfterWrite(5 * 60 * 1000)   // background refresh every 5 min
  .onEviction((key, value, reason) => {
    console.log(`Guild ${key} evicted: ${reason}`);
  })
  .buildAsync(async (guildId) => {
    let doc = await Guild.findById(guildId);
    if (!doc) doc = await new Guild({ _id: guildId }).save();
    return doc;
  });

// Usage in commands:
const settings = await guildCache.get(interaction.guildId);

// After a dashboard save:
guildCache.invalidate(guildId);

Member stats cache

const memberCache = CacheBuilder.newBuilder()
  .maximumSize(1000)
  .expireAfterWrite(10 * 60 * 1000) // expire 10 min after last write
  .buildAsync(async (key) => {
    const [guildId, memberId] = key.split('|');
    return MemberStats.findOne({ guild_id: guildId, member_id: memberId });
  });

const stats = await memberCache.get(`${guildId}|${memberId}`);
stats.xp += 10;
await stats.save();
memberCache.invalidate(`${guildId}|${memberId}`); // bust cache after save

Per-call loader (no bound loader)

const cache = CacheBuilder.newBuilder()
  .maximumSize(100)
  .expireAfterWrite(60_000)
  .build(); // no bound loader

// Pass loader on each call:
const data = await cache.get('api-response', async (key) => {
  return fetch(`https://api.example.com/${key}`).then(r => r.json());
});

Manual writes with put()

// Pre-warm the cache or write without loading
cache.put('guild:123', { prefix: '!', lang: 'pt' });
cache.getIfPresent('guild:123'); // → { prefix: '!', lang: 'pt' }

API Reference

CacheBuilder.newBuilder()

| Method | Description | |--------|-------------| | .maximumSize(n) | Max entries before LRU eviction | | .expireAfterWrite(ms) | Expire N ms after last write | | .expireAfterAccess(ms) | Expire N ms after last read | | .refreshAfterWrite(ms) | Background refresh after N ms (stale-while-revalidate) | | .onEviction(fn) | (key, value, reason) => void callback | | .build() | Build without bound loader — pass loader per get() call | | .buildAsync(loader) | Build with bound async (key) => value loader |

CaffeineCache

| Method | Description | |--------|-------------| | get(key, loader?) | Get value, loading if missing or expired | | put(key, value) | Manual write | | getIfPresent(key) | Get only if cached and not expired | | has(key) | Check existence | | invalidate(key) | Remove one key | | invalidateAll() | Clear entire cache | | cleanUp() | Proactively evict expired entries | | stats | { hits, misses, loads, errors, evictions, refreshes, size, inflight } |

Links