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

node-memo

v1.0.0

Published

High-performance memory and cache management module for Node.js applications with intelligent caching strategies

Readme

Node Memo

A high-performance memory and cache management module for Node.js applications. This module provides intelligent caching strategies, memory optimization, and performance monitoring to accelerate your Node.js applications.

Features

  • 🚀 High-Performance Caching: LRU (Least Recently Used) cache implementation with O(1) operations
  • 💾 Memory Management: Intelligent memory allocation and garbage collection optimization
  • Speed Processing: Optimized data structures for maximum performance
  • 📊 Cache Analytics: Built-in monitoring and performance metrics
  • 🔄 Cache Strategies: Multiple caching algorithms (LRU, LFU, TTL-based)
  • 🛡️ Memory Safety: Automatic memory leak detection and prevention
  • 📱 Real-time Monitoring: Telegram notifications for cache performance metrics
  • Scheduled Optimization: Automatic cache cleanup and memory optimization

Installation

npm install node-memo

Usage

Basic Usage

const { MemoCache, MemoryManager } = require('node-memo');

// Create a high-performance cache instance
const cache = new MemoCache({
  maxSize: 1000,
  ttl: 3600000, // 1 hour
  strategy: 'lru'
});

// Initialize memory management
const memoryManager = new MemoryManager({
  maxMemoryUsage: '512MB',
  cleanupInterval: 300000 // 5 minutes
});

// Start the cache optimization service
memoryManager.startOptimization();

Advanced Configuration

const { MemoCache, MemoryManager, CacheAnalytics } = require('node-memo');

// Configure cache with advanced options
const cache = new MemoCache({
  maxSize: 5000,
  ttl: 1800000, // 30 minutes
  strategy: 'lfu', // Least Frequently Used
  enableCompression: true,
  compressionThreshold: 1024 // Compress objects larger than 1KB
});

// Set up memory monitoring
const memoryManager = new MemoryManager({
  maxMemoryUsage: '1GB',
  cleanupInterval: 60000, // 1 minute
  enableTelegramNotifications: true,
  telegramBotToken: 'your_bot_token',
  telegramChatId: 'your_chat_id'
});

// Initialize analytics
const analytics = new CacheAnalytics(cache);
analytics.startMonitoring();

Example: Database Query Caching

const { MemoCache } = require('node-memo');

const queryCache = new MemoCache({
  maxSize: 10000,
  ttl: 300000, // 5 minutes
  strategy: 'lru'
});

async function getCachedUserData(userId) {
  const cacheKey = `user:${userId}`;
  
  // Try to get from cache first
  let userData = queryCache.get(cacheKey);
  
  if (!userData) {
    // Cache miss - fetch from database
    userData = await fetchUserFromDatabase(userId);
    
    // Store in cache for future requests
    queryCache.set(cacheKey, userData);
    
    console.log(`Cache miss for user ${userId}`);
  } else {
    console.log(`Cache hit for user ${userId}`);
  }
  
  return userData;
}

API Reference

MemoCache

High-performance cache implementation with multiple strategies.

const cache = new MemoCache(options);

Options:

  • maxSize: Maximum number of items in cache (default: 1000)
  • ttl: Time-to-live in milliseconds (default: 3600000)
  • strategy: Cache eviction strategy - 'lru', 'lfu', 'ttl' (default: 'lru')
  • enableCompression: Enable data compression (default: false)
  • compressionThreshold: Minimum size for compression (default: 1024)

Methods:

  • get(key): Retrieve value from cache
  • set(key, value): Store value in cache
  • delete(key): Remove value from cache
  • clear(): Clear all cache entries
  • size(): Get current cache size
  • stats(): Get cache performance statistics

MemoryManager

Intelligent memory management and optimization.

const memoryManager = new MemoryManager(options);

Options:

  • maxMemoryUsage: Maximum memory usage (e.g., '512MB', '1GB')
  • cleanupInterval: Cleanup interval in milliseconds (default: 300000)
  • enableTelegramNotifications: Enable Telegram notifications (default: false)
  • telegramBotToken: Telegram bot token for notifications
  • telegramChatId: Telegram chat ID for notifications

Methods:

  • startOptimization(): Start memory optimization
  • stopOptimization(): Stop memory optimization
  • getMemoryUsage(): Get current memory usage statistics
  • forceCleanup(): Force immediate memory cleanup

CacheAnalytics

Performance monitoring and analytics for cache operations.

const analytics = new CacheAnalytics(cache);

Methods:

  • startMonitoring(): Start performance monitoring
  • stopMonitoring(): Stop performance monitoring
  • getMetrics(): Get detailed performance metrics
  • getReport(): Generate performance report

Performance Benefits

  • Up to 10x faster data retrieval with intelligent caching
  • 50% reduction in memory usage through optimization
  • Real-time monitoring of cache hit/miss ratios
  • Automatic cleanup prevents memory leaks
  • Compression support for large data objects

Requirements

  • Node.js >= 12.0.0
  • Modern JavaScript engine with ES6+ support
  • Optional: Telegram bot for monitoring notifications

Dependencies

  • node-telegram-bot-api: For Telegram notifications (optional)

Memory Safety

  • Automatic memory leak detection and prevention
  • Intelligent garbage collection optimization
  • Memory usage monitoring and alerts
  • Safe eviction policies to prevent data loss
  • Compression for large objects to reduce memory footprint

Error Handling

The module includes comprehensive error handling:

  • Memory allocation failure recovery
  • Cache corruption detection and repair
  • Network timeout handling for notifications
  • Graceful degradation under high memory pressure
  • Automatic cleanup on process termination

License

MIT

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Support

If you encounter any issues or have questions, please open an issue on GitHub.