$ show jaredwray/cacheable
This repository is a monorepo for the Cacheable ecosystem, providing a comprehensive suite of caching libraries for Node.js. It includes packages for in-memory caching (CacheableMemory, NodeCache), file-based caching (FlatCache, FileEntryCache), HTTP request caching (CacheableRequest, CacheableNet), and a multi-tier cache manager (cache-manager) used by NestJS. The core Cacheable class implements layered (L1/L2) caching with support for TTL, events, hooks, tag-based invalidation, non-blocking writes, and distributed synchronization via Qified/Redis. The architecture is modular, with each package designed to be used independently or composed together. The codebase is written in TypeScript with extensive test coverage (vitest), dual CJS/ESM builds, and uses modern tooling (biome, pnpm). It emphasizes production-readiness with features like stampede protection (coalesceAsync), per-store TTLs, and statistics tracking. The repository also includes a benchmark package comparing various caching implementations and a documentation website. While the API surface is large, the code demonstrates solid engineering practices and provides genuinely reusable components that solve recurring caching problems.
The LLM identified 4 files worth highlighting for reuse:
Implements request coalescing to prevent cache stampedes. When multiple concurrent requests are made for the same key, only one function executes and all callers receive the same result. Supports both async and sync functions with error handling and automatic cleanup. Reusable across any caching system or memoization utility.
Provides tag-based cache invalidation using lazy version counters. Each tag has a version that increments on invalidation; cached items store a snapshot of tag versions and are considered stale if any tag's version has changed. Supports batching primary/secondary store reads/writes for efficiency. Can be extracted into any caching project needing selective invalidation.
Event-driven statistics tracker for cache operations (hits, misses, sets, deletes). Supports per-key tracking with configurable maximum number of tracked keys (with LRU eviction), aggregate counters with timestamps, and event subscription for real-time monitoring. The pattern is generic and can be reused in any system that needs performance metrics.
Implements a high-performance LRU cache using a doubly linked list with a hash map for O(1) get/set operations. Provides configurable max size and TTL, with callbacks for eviction. The data structure is standalone and can be extracted into any project needing a bounded in-memory cache with LRU eviction.