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

@beatsphere/cache-utils

v0.1.0

Published

LRU, TTL, and ETag cache implementations with zero dependencies

Downloads

62

Readme

@beatsphere/cache-utils

Three complementary in-memory cache implementations with zero dependencies. Battle-tested in BeatSphere.

Install

npm install @beatsphere/cache-utils

Caches

LRUCache

Least Recently Used cache with O(1) get/set. When full, evicts the item that hasn't been accessed the longest.

import { LRUCache } from '@beatsphere/cache-utils';

const cache = new LRUCache<string, object>(100); // max 100 items

cache.set('user:1', { name: 'Alice' });
cache.get('user:1'); // moves to most-recently-used
cache.size;          // 1
cache.getStats();    // { size: 1, maxSize: 100, utilizationPercent: 1 }

TTLCache

Time-to-live cache with automatic expiration and background cleanup.

import { TTLCache } from '@beatsphere/cache-utils';

const cache = new TTLCache<string, string>(
  30_000,   // 30s TTL
  500,      // max 500 items (default: 1000)
  60_000    // cleanup every 60s (default)
);

cache.set('token', 'abc123');
cache.get('token'); // 'abc123'

// After 30 seconds...
cache.get('token'); // undefined (expired)

// When done:
cache.destroy(); // stops cleanup interval

ETagCache

Stores HTTP ETags alongside response data for If-None-Match / 304 Not Modified flows.

import { ETagCache } from '@beatsphere/cache-utils';

const cache = new ETagCache(5 * 60 * 1000); // 5 min expiry (default)

// After a successful response:
cache.set('/api/users', response.headers.etag, response.data);

// Before the next request:
const etag = cache.getETag('/api/users');
if (etag) {
  // Send If-None-Match: etag
  // On 304: use cache.get('/api/users').data
}

API

LRUCache<K, V>

| Method | Returns | Description | |--------|---------|-------------| | new LRUCache(maxSize) | | Create cache with max capacity | | get(key) | V \| undefined | Get value, moves to most-recent | | set(key, value) | void | Set value, evicts LRU if full | | has(key) | boolean | Check existence | | delete(key) | boolean | Remove entry | | clear() | void | Remove all entries | | size | number | Current item count | | keys() | K[] | Keys, least to most recent | | values() | V[] | Values, least to most recent | | entries() | [K, V][] | Entries, least to most recent | | getStats() | object | Size, maxSize, utilization % |

TTLCache<K, V>

| Method | Returns | Description | |--------|---------|-------------| | new TTLCache(ttlMs, maxSize?, cleanupMs?) | | Create cache | | get(key) | V \| undefined | Get value if not expired | | set(key, value) | void | Set value with TTL | | has(key) | boolean | Check existence (non-expired) | | delete(key) | boolean | Remove entry | | clear() | void | Remove all entries | | destroy() | void | Stop cleanup interval and clear | | size | number | Current item count | | keys() | K[] | All keys (may include expired) | | values() | V[] | Non-expired values only | | entries() | [K, V][] | Non-expired entries only | | getStats() | object | Size, maxSize, ttlMs, utilization % |

ETagCache

| Method | Returns | Description | |--------|---------|-------------| | new ETagCache(maxAgeMs?) | | Create cache (default: 5 min) | | get(url) | { etag, data } \| null | Get cached entry | | set(url, etag, data) | void | Store ETag + data | | getETag(url) | string \| null | Get just the ETag | | delete(url) | void | Remove entry | | clear() | void | Remove all entries | | size | number | Current item count |

License

MIT