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

fs-cachebox

v1.1.3

Published

A lightweight file-based caching library for Node.js. Stores key-value data on the filesystem with optional TTL support.

Downloads

19

Readme

CacheBox

A fast, feature-rich file-based cache system for Node.js with compression, TTL, and event support.

Features

  • 🚀 Fast: Both sync and async operations
  • 💾 Persistent: File-based storage survives restarts
  • 🗜️ Compression: Optional gzip compression for large values
  • TTL Support: Automatic expiration of cache entries
  • 🧹 Auto Cleanup: Removes expired entries automatically
  • 📊 Statistics: Built-in performance monitoring
  • 🔒 Safe: Key validation and error handling
  • 📦 Batch Operations: Set/get multiple entries at once

Installation

npm install fs-cachebox

Quick Start

import { CacheBox } from 'fs-cachebox';

// Create cache instance
const cache = new CacheBox({
  cacheDir: './my-cache',
  enableCompression: true,
  defaultTTL: 60000 // 1 minute
});

// Store data
cache.set('user:123', { name: 'John', age: 30 });

// Retrieve data
const user = cache.get('user:123');
console.log(user); // { name: 'John', age: 30 }

// Check if key exists
if (cache.has('user:123')) {
  console.log('User found!');
}

// Set with custom TTL (5 seconds)
cache.set('temp-data', 'expires soon', 5000);

// Delete entry
cache.delete('user:123');

Configuration Options

const cache = new CacheBox({
  cacheDir: '.cache',              // Cache directory
  enableCompression: false,        // Enable gzip compression
  compressionThreshold: 1024,      // Min size for compression (bytes)
  compressionLevel: 6,             // Compression level (1-9)
  maxSize: 1000,                   // Max cache entries
  maxFileSize: 50 * 1024 * 1024,   // Max file size (50MB)
  defaultTTL: 0,                   // Default TTL (0 = no expiration)
  cleanupInterval: 300000,         // Cleanup interval (5 minutes)
  enableAutoCleanup: true,         // Auto cleanup expired entries
  enableLogging: false             // Enable debug logging
});

Async Operations

// Async operations for better performance
const user = await cache.getAsync('user:123');
await cache.setAsync('user:456', userData, 30000);
await cache.deleteAsync('user:123');

// Batch operations
await cache.setManyAsync([
  { key: 'user:1', value: userData1 },
  { key: 'user:2', value: userData2, ttl: 60000 }
]);

const results = await cache.getManyAsync(['user:1', 'user:2']);

Events

cache.on('ready', ({ entriesLoaded, cacheDir }) => {
  console.log(`Cache ready with ${entriesLoaded} entries`);
});

cache.on('change', ({ operation, key }) => {
  console.log(`${operation} performed on ${key}`);
});

cache.on('expire', ({ key, ttl }) => {
  console.log(`Key ${key} expired`);
});

cache.on('error', (error) => {
  console.error('Cache error:', error);
});

Statistics & Monitoring

// Get performance stats
const stats = cache.stats();
console.log(`Hit rate: ${(stats.performance.hitRate * 100).toFixed(2)}%`);
console.log(`Total entries: ${stats.entries}`);
console.log(`Cache size: ${stats.totalSize} bytes`);

// Manual cleanup
const { expired, removed } = cache.cleanup();
console.log(`Cleaned up ${expired} expired, ${removed} evicted entries`);

// Get all keys
const keys = cache.keys();
console.log('Cached keys:', keys);

Error Handling

try {
  const result = cache.get('some-key');
  if (result === null) {
    console.log('Key not found or expired');
  }
} catch (error) {
  if (error instanceof CacheError) {
    console.error(`Cache operation failed: ${error.operation}`);
  }
}

// Listen for errors
cache.on('error', (error) => {
  console.error('Cache error:', error.message);
});

Best Practices

  • Use compression for large objects (>1KB)
  • Set appropriate TTL values to prevent memory bloat
  • Monitor cache hit rates with cache.stats()
  • Use async methods for better performance in I/O heavy applications
  • Handle cache misses gracefully in your application logic

License

ISC

Contributing

Pull requests are welcome! Please ensure tests pass and follow the existing code style.