A high-performance, in-memory caching library for TypeScript. TTL expiration, LRU eviction, and a powerful @cached decorator—all in a zero-dependency package.
Simple, fast, and reliable caching for your TypeScript applications.
In-memory storage with O(1) lookups. No network latency, no disk I/O—just pure speed.
Set time-to-live for cache entries. Expired items are automatically cleaned up.
Smart eviction policy removes least recently used items when the cache reaches max size.
Automatic method-level caching with a simple decorator. No boilerplate required.
Full type safety with generics. Your cached values are properly typed.
Lightweight and self-contained. No bloat, no supply chain risks.
Get started in seconds with simple, intuitive APIs.
import { MemoryCache, cached } from '@humanspeak/memory-cache'
// Create a cache with 5 minute TTL and max 100 items
const cache = new MemoryCache<User>({
ttl: 300000,
maxSize: 100
})
// Simple get/set operations
cache.set('user:123', { name: 'Alice' })
const user = cache.get('user:123')
// Or use the @cached decorator
class UserService {
@cached({ ttl: 60000 })
async getUser(id: string) {
return await fetchUserFromDb(id)
}
}