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 🙏

© 2025 – Pkg Stats / Ryan Hefner

min-cache

v0.1.5

Published

Ultra-lightweight in-memory cache with TTL

Downloads

25

Readme

MinCache

Ultra-lightweight, in-memory cache for Node.js with TTL support and configurable size limits.

Features

  • In-memory storage for fast access
  • Time-to-live (TTL) for each record (ms)
  • Max cache size (in KB) with automatic clearing oldest or expired records
  • Customizable options (debug, TTL, cleanup interval)
  • Redis-like method names (SET, GET, DEL, etc.)
  • TypeScript support

Installation

npm install min-cache

Usage

import MinCache from 'min-cache';

const cache = new MinCache('myCache', {
  maxSizeKb: 5 * 1024,    // Max cache size in KB
  clearExpiredMs: 60000,  // Clear interval
  ttlMs: 30000,           // Default TTL for items (ms)
  debug: true             // On/Off logging
});

// Add an item
cache.set('key', { foo: 'bar' }, 10000); // TTL: 10s

// Get an item
const value = cache.get('key');

// Check if a key exists
const exists = cache.exists('key');

// Remove a key
cache.del('key');

// Get list of all keys
const keys = cache.keys();

// Get all valid items
const all = cache.getAll();

// Set a new TTL for a key
cache.setTtl('key', 20000); // exact 20 seconds from now

// Find up all keys starting with "userid"
const matches = cache.scan('user*');

// Find up maximum 10 keys starting with "userid"
const matchesLimited = cache.scan('user*', 10);

API

Constructor

new MinCache(id: string, options?: CacheOptions)
  • id: Unique cache name (for logging/debugging)
  • options:
    • maxSizeKb (number): Max cache size in KB (default: 5000)
    • clearExpiredMs (number): How often to clear expired items (default: 10000)
    • ttlMs (number): Default TTL for items in ms (default: 60000)
    • debug (boolean): Enable debug logging (default: false)

Methods

  • set(key, value, ttlMs?): Add item with optional TTL
  • get(key): Get item by key
  • exists(key): Check if key exists and is not expired
  • del(key): Remove item by key
  • delAll(): Remove all items
  • delExpired(): Remove all expired items
  • keys(): Get all valid keys
  • getAll(): Get all valid items
  • ttl(key): Get time-to-live (seconds) for a key
  • setTtl(key, ttlMs): Set new TTL for a key
  • rename(oldKey, newKey): Rename a key
  • scan(pattern, count?): Get up to count keys matching a pattern (e.g. userid*). Returns an array of matching keys.