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

memoru

v1.1.2

Published

A hash-based LRU cache that evicts entries based on memory usage rather than time or item count.

Readme

memoru

NPM Version Downloads Count Vulnerabilities Count Release License Codecov

A hash-based LRU cache for Node.js that evicts entries based on memory usage or item count. Designed for high performance and low memory overhead, with TypeScript support and memory monitoring utilities.

ToC

Features

  • Fast hash-based LRU cache with O(1) operations
  • Eviction based on memory usage or item count
  • Optional integration with Node.js memory stats
  • Garbage collection monitoring to prevent rotations during GC
  • TypeScript support and strict types
  • Zero dependencies
  • Suitable for caching in memory-constrained environments

Installation

NPM:

npm install memoru

PNPM:

pnpm add memoru

Usage

Basic LRU Usage

import { Memoru } from 'memoru';

const lru = new Memoru({ max: 100 }); // max 100 items
lru.set('foo', 'bar');
console.log(lru.get('foo')); // 'bar'

Memory Threshold Eviction

Evict items automatically when process memory or V8 heap usage exceeds a threshold:

import { Memoru, ProcessMemoryStat } from 'memoru';

const lru = new Memoru({
  max: 1000,
  memoryStats: {
    monitored: [
      { stat: ProcessMemoryStat.RSS, threshold: 100 * 1024 * 1024 }, // 100MB
    ],
    interval: 1000, // check every second
  },
});

TypeScript Support

All APIs are fully typed:

import { Memoru } from 'memoru';

const lru = new Memoru<string, number>({ max: 10 });
lru.set('a', 1);
const value: number | undefined = lru.get('a');

Memory Monitoring Utilities

You can use the memory stats monitor directly:

import { MemoryStatsMonitor, ProcessMemoryStat } from 'memoru';

const monitor = new MemoryStatsMonitor({
  monitored: [{ stat: ProcessMemoryStat.RSS, threshold: 200 * 1024 * 1024 }],
  interval: 5000,
});

monitor.on('threshold', (stat) => {
  console.log('Memory threshold exceeded for', stat);
});

GC Monitoring

You can enable garbage collection monitoring to prevent cache rotations during garbage collection:

import { HeapSpace, Memoru } from 'memoru';

const lru = new Memoru({
  max: 1000,
  respectGC: true, // Prevent rotations during GC
  memoryStats: {
    monitorGC: true, // Enable GC monitoring
    gcCooldown: 500, // Wait 500ms after GC before allowing rotations
    monitored: [
      { stat: HeapSpace.Old, threshold: 50 * 1024 * 1024 }, // 50MB
    ],
    interval: 1000,
  },
});

Note: GC monitoring uses Node.js PerformanceObserver API and works without additional flags.


## Demo

```typescript
import { Memoru } from 'memoru';

const lru = new Memoru({ max: 2 });
lru.set('a', 1);
lru.set('b', 2);
lru.set('c', 3); // 'a' is evicted
console.log(lru.get('a')); // undefined
console.log(lru.get('b')); // 2
console.log(lru.get('c')); // 3

See also

  • hashlru - inspiration for the core algorithm
  • lru-cache - another popular LRU cache for Node.js