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

memstashjs

v1.0.1

Published

Performance-first in-memory cache with TTL (time-to-live) support. Works in Node.js and all modern browsers. Zero dependencies, blazing fast O(1) lookups using native Map.

Readme

memstashjs

Performance-first in-memory cache with TTL (time-to-live) support. Works in Node.js and all modern browsers. Zero dependencies, blazing fast O(1) lookups using native Map.

npm version license


Features

  • O(1) Lookups -- Built on native JavaScript Map for constant-time reads and writes.
  • TTL Support -- Set expiration time per key in milliseconds. Expired entries are lazily cleaned on access.
  • Singleton + Instance -- Use the pre-created default instance or create multiple isolated caches.
  • Isomorphic -- Works in Node.js, Deno, Bun, and all modern browsers.
  • Zero Dependencies -- Nothing to install besides this package.
  • Tiny Footprint -- Under 2KB unminified.

Installation

npm install memstashjs

Usage

Basic Caching

const cache = require('memstashjs');

// Store a value (no expiry)
cache.set('config', { theme: 'dark', lang: 'en' });

// Retrieve it
const config = cache.get('config');
console.log(config);
// { theme: 'dark', lang: 'en' }

Caching with TTL (Time To Live)

const cache = require('memstashjs');

// Cache a user session for 30 minutes (1800000ms)
cache.set('session:abc123', {
  userId: 42,
  role: 'admin',
  loginTime: Date.now()
}, 1800000);

// Immediately available
console.log(cache.get('session:abc123'));
// { userId: 42, role: 'admin', loginTime: ... }

// After 30 minutes, automatically returns null
// console.log(cache.get('session:abc123'));
// null

Checking Key Existence

const cache = require('memstashjs');

cache.set('token', 'xyz', 5000);

console.log(cache.has('token'));  // true
console.log(cache.has('other'));  // false

// After 5 seconds:
// console.log(cache.has('token'));  // false

Deleting a Key

const cache = require('memstashjs');

cache.set('temp', 'data');
cache.delete('temp');

console.log(cache.get('temp'));
// null

Clearing All Entries

const cache = require('memstashjs');

cache.set('a', 1);
cache.set('b', 2);
cache.set('c', 3);

cache.clear();

console.log(cache.get('a'));  // null
console.log(cache.get('b'));  // null
console.log(cache.get('c'));  // null

Multiple Isolated Cache Instances

const { MemStash } = require('memstashjs');

const userCache = new MemStash();
const productCache = new MemStash();

userCache.set('u1', { name: 'Alice' });
productCache.set('p1', { name: 'Widget', price: 9.99 });

// These are completely separate stores
console.log(userCache.get('p1'));     // null
console.log(productCache.get('u1')); // null

Caching API Responses

const cache = require('memstashjs');

async function getUser(id) {
  const cacheKey = `user:${id}`;

  // Check cache first
  const cached = cache.get(cacheKey);
  if (cached) return cached;

  // Fetch from API
  const response = await fetch(`https://api.example.com/users/${id}`);
  const user = await response.json();

  // Cache for 5 minutes
  cache.set(cacheKey, user, 300000);

  return user;
}

API Reference

| Method | Parameters | Returns | Description | | --- | --- | --- | --- | | set(key, value, ttl) | key: string, value: any, ttl: number (optional, ms) | void | Stores a value with optional expiration | | get(key) | key: string | any or null | Retrieves a value, returns null if expired or missing | | has(key) | key: string | boolean | Checks if a non-expired key exists | | delete(key) | key: string | void | Removes a specific key | | clear() | -- | void | Removes all entries |


License

MIT -- see LICENSE for details.