@flightdev/cache-lru
v0.0.8
Published
LRU (Least Recently Used) cache adapter for Flight Framework - bounded memory cache with eviction
Downloads
11
Maintainers
Readme
@flightdev/cache-lru
In-memory LRU cache adapter for Flight Framework. Fast, size-bounded caching.
Installation
npm install @flightdev/cache-lruQuick Start
import { createCache } from '@flightdev/core/cache';
import { lru } from '@flightdev/cache-lru';
const cache = createCache(lru({
max: 1000, // Max entries
ttl: 60 * 1000, // Default TTL in ms
}));
await cache.set('key', 'value');
const value = await cache.get('key');Configuration
lru({
// Maximum number of entries
max: 1000,
// Maximum size in bytes (alternative to max)
maxSize: 50 * 1024 * 1024, // 50MB
// Size calculator for maxSize
sizeCalculation: (value) => JSON.stringify(value).length,
// Default TTL in milliseconds
ttl: 60 * 1000,
// Update TTL on access
updateAgeOnGet: true,
// Allow stale values while revalidating
allowStale: true,
});Features
- O(1) get/set/delete operations
- Size-bounded with LRU eviction
- TTL support
- Stale-while-revalidate
- No external dependencies
License
MIT
