@flight-framework/cache-tiered
v0.0.7
Published
Tiered/layered cache adapter for Flight Framework - combine multiple cache layers
Maintainers
Readme
@flight-framework/cache-tiered
Tiered cache adapter for Flight Framework. Combine multiple cache layers for optimal performance.
Installation
npm install @flight-framework/cache-tieredQuick Start
import { createCache } from '@flight-framework/core/cache';
import { tiered } from '@flight-framework/cache-tiered';
import { lru } from '@flight-framework/cache-lru';
import { redis } from '@flight-framework/cache-redis';
const cache = createCache(tiered([
lru({ max: 100, ttl: 60000 }), // L1: Fast in-memory
redis({ url: process.env.REDIS_URL }), // L2: Shared Redis
]));
// Reads check L1 first, then L2
// Writes go to all layers
await cache.set('key', 'value');
const value = await cache.get('key');Configuration
tiered([
// Layers in order of priority (fastest first)
memoryAdapter,
redisAdapter,
s3Adapter, // For very large/cold data
], {
// Write to all layers on set (default: true)
writeThrough: true,
// Populate faster layers on cache miss (default: true)
populateOnMiss: true,
});How It Works
- Read: Check L1 -> L2 -> L3 until found
- Write: Write to all layers
- Miss: Populate faster layers with the value
License
MIT
