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

ltcache

v0.2.0

Published

A lightweight, in-memory caching library - like Redis but much simpler. Features TTL support, concurrent request handling, and comprehensive statistics. Perfect for Node.js applications that need fast caching without the complexity of Redis.

Readme

ltcache

A lightweight, in-memory caching library - like Redis but much simpler. Features TTL support, concurrent request handling, and comprehensive statistics. Perfect for Node.js applications and frontend applications that need fast caching without the complexity of Redis.

build status License: MIT TypeScript SemVer Conventional Commits AutoRel

✨ Features

  • 🚀 Lightweight: Zero external dependencies, minimal memory footprint
  • ⏱️ TTL Support: Automatic expiration with configurable time-to-live
  • 🔄 Concurrent Safe: Multiple simultaneous requests for the same key only call the function once
  • 📊 Statistics: Built-in hit rate tracking and cache size monitoring
  • 🎯 Pattern Removal: Remove multiple keys using regex patterns
  • 🔒 TypeScript: Full type safety with generics
  • ⚡ Fast: In-memory storage for maximum performance
  • 🌐 Universal: Works in Node.js, browsers, React, Vue, and other frontend frameworks

📦 Installation

npm install ltcache

🚀 Quick Start

import {cache} from 'ltcache';

// Create a cache instance
const cacheInstance = cache();

// Create a cache instance with debug logging enabled
const debugCache = cache(true);

// Simple caching
cacheInstance.set('user:123', {name: 'Alice', email: '[email protected]'}, 3600); // 1 hour TTL
const user = await cacheInstance.get('user:123');

// Caching with fallback function
const user = await cacheInstance.get('user:123', async () => {
  // This function only runs if the key doesn't exist
  return await fetchUserFromDatabase(123);
}, 3600); // Cache for 1 hour

// Get cache statistics
const stats = cacheInstance.report();
console.log(`Hit rate: ${stats.hitRate}%`);

📚 Documentation

🎯 Use Cases

Perfect for:

  • API Response Caching: Cache expensive API calls
  • Database Query Results: Store frequently accessed data
  • Configuration Storage: Cache app configuration
  • Session Data: Store temporary user session information
  • Microservices: Lightweight caching between services
  • Frontend Apps: Cache API responses, user preferences, and computed data in React, Vue, and other frameworks
  • Browser Storage: Lightweight alternative to localStorage with TTL support
  • SPA Performance: Improve app responsiveness by caching expensive operations

When to use ltcache vs Redis:

Use ltcache when:

  • You need simple, fast caching
  • You want zero external dependencies
  • Your cache fits in memory
  • You don't need persistence across restarts
  • You want minimal setup and configuration
  • You're building frontend applications (React, Vue, etc.) and need client-side caching

Use Redis when:

  • You need persistence across application restarts
  • You need to share cache across multiple applications (though ltcache could be used as the foundation for a Redis-style server)
  • You need advanced data structures (lists, sets, etc.)
  • You need pub/sub functionality
  • You need clustering or replication

🔧 Advanced Usage

Debug Mode

Enable debug logging to see cache operations in real-time:

// Create cache with debug logging enabled
const cache = cache(true);

// All cache operations will now log to console
await cache.get('user:123', async () => {
  return await fetchUserFromDatabase(123);
});
// Output: miss: user:123
// Output: set: user:123

await cache.get('user:123');
// Output: hit: user:123

Concurrent Request Handling

// Multiple simultaneous requests for the same key
const promises = [
  cache.get('expensive-data', async () => {
    await new Promise(resolve => setTimeout(resolve, 1000));
    return 'result';
  }),
  cache.get('expensive-data', async () => {
    await new Promise(resolve => setTimeout(resolve, 1000));
    return 'result';
  }),
  cache.get('expensive-data', async () => {
    await new Promise(resolve => setTimeout(resolve, 1000));
    return 'result';
  })
];

const results = await Promise.all(promises);
// All three promises resolve to the same value
// The expensive function is only called once

Pattern-based Removal

// Cache some data
cache.set('user:123:profile', profileData);
cache.set('user:123:settings', settingsData);
cache.set('user:456:profile', profileData2);
cache.set('config:app', appConfig);

// Remove all user data for user 123
cache.remove(/^user:123:/);

// Remove all user profiles
cache.remove(/^user:.*:profile$/);

// Remove all config
cache.remove(/^config:/);

Cache Statistics

const stats = cache.report();
console.log({
  items: stats.numItems,        // Number of cached items
  hitRate: stats.hitRate,       // Hit rate percentage
  sizeKb: stats.sizeKb          // Estimated memory usage
});

🧪 Testing

npm test

📄 License

MIT License - see LICENSE file for details.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📈 Performance

ltcache is designed for speed and efficiency:

  • Memory efficient: Uses Map for O(1) lookups
  • Concurrent safe: Handles multiple simultaneous requests efficiently
  • Minimal overhead: Zero external dependencies
  • Fast expiration: Efficient timeout management

🔗 Related Projects

  • Redis - Full-featured in-memory data store
  • node-cache - Another Node.js caching library
  • lru-cache - LRU cache implementation

Made with ❤️ by Marc H. Weiner