🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

node-memo

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-memo

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

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

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

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

Support

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

Keywords

cache

FAQs

Package last updated on 22 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts