Simple and extensible caching module for TypeScript/Node.js with decorator support.
- Decorator-based caching - Use
@Cache,@SyncCache, and@MultiCachedecorators for elegant caching - Multiple storage backends - Memory, File System, Redis, LRU Cache, and more
- Flexible expiration strategies - TTL-based expiration with lazy or eager invalidation
- Multi-tier caching - Chain multiple cache layers (e.g., local LRU + remote Redis)
- TypeScript-first - Full type safety with comprehensive interfaces
- ESM support - Modern ES modules with Node.js 18+
npm install @node-ts-cache/coreimport { Cache, ExpirationStrategy, MemoryStorage } from '@node-ts-cache/core';
const cacheStrategy = new ExpirationStrategy(new MemoryStorage());
class UserService {
@Cache(cacheStrategy, { ttl: 300 })
async getUser(id: string): Promise<User> {
// This result will be cached for 5 minutes
return await fetchUserFromDatabase(id);
}
}This is a monorepo containing the following packages:
| Package | Version | Description |
|---|---|---|
| @node-ts-cache/core | Core caching module with decorators, strategies, and built-in storages |
| Package | Version | Description |
|---|---|---|
| @node-ts-cache/redis-storage | Redis storage using redis package (v4.x) |
|
| @node-ts-cache/ioredis-storage | Redis storage using ioredis with compression support |
|
| @node-ts-cache/node-cache-storage | In-memory cache using node-cache |
|
| @node-ts-cache/lru-storage | LRU cache with automatic eviction | |
| @node-ts-cache/lru-redis-storage | Two-tier caching (local LRU + remote Redis) | |
| @node-ts-cache/elasticsearch-storage | Elasticsearch storage for search-optimized caching | |
| @node-ts-cache/memcached-storage | Memcached storage for distributed caching | |
| @node-ts-cache/valkey-storage | Valkey storage (Redis-compatible, open source) |
For detailed documentation, see the main package README.
┌─────────────────────────────────────────────────────────────────┐
│ Application │
├─────────────────────────────────────────────────────────────────┤
│ Decorators Layer │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ @Cache │ │ @SyncCache │ │ @MultiCache │ │
│ │ (async) │ │ (sync) │ │ (multi-tier/batch) │ │
│ └──────┬──────┘ └──────┬──────┘ └──────────┬──────────┘ │
├──────────┼────────────────┼────────────────────┼────────────────┤
│ └────────────────┼────────────────────┘ │
│ ▼ │
│ ┌────────────────┐ │
│ │ Strategy │ │
│ │ (Expiration) │ │
│ └───────┬────────┘ │
├──────────────────────────┼──────────────────────────────────────┤
│ ▼ │
│ ┌──────────────────────────────────────────────────────────────────────────────────┐ │
│ │ Storage Layer │ │
│ ├────────┬──────┬───────┬─────┬───────────┬───────────────┬────────────┬──────────┤ │
│ │ Memory │ FS │ Redis │ LRU │ LRU+Redis │ Elasticsearch │ Memcached │ Valkey │ │
│ └────────┴──────┴───────┴─────┴───────────┴───────────────┴────────────┴──────────┘ │
└─────────────────────────────────────────────────────────────────┘
| Storage | Type | Use Case | Features |
|---|---|---|---|
| MemoryStorage | Sync | Development, small datasets | Zero config, bundled |
| FsJsonStorage | Async | Persistent local cache | File-based, survives restarts |
| NodeCacheStorage | Sync | Production single-instance | TTL support, multi-ops |
| LRUStorage | Sync | Memory-constrained apps | Auto-eviction, size limits |
| RedisStorage | Async | Distributed systems | Shared cache, redis v4 |
| RedisIOStorage | Async | Distributed systems | Compression, modern ioredis |
| LRUWithRedisStorage | Async | High-performance distributed | Local + remote tiers |
| ElasticsearchStorage | Async | Search-integrated caching | Full-text search, scalable |
| MemcachedStorage | Async | High-performance distributed | Simple, fast, widely supported |
| ValkeyStorage | Async | Distributed systems | Redis-compatible, open source |
- Node.js >= 18.0.0
- TypeScript >= 5.0 (for decorator support)
# Install dependencies
npm install
# Build all packages
npm run build
# Run tests
npm testContributions are welcome! Please feel free to submit a Pull Request.
MIT License - see LICENSE for details.