Cache
@veloxts/cache provides a unified caching API.
Installation
Section titled “Installation”pnpm add @veloxts/cacheQuick Start
Section titled “Quick Start”import { cachePlugin } from '@veloxts/cache';
app.register(cachePlugin, { driver: 'memory', config: { maxSize: 1000 },});Basic Usage
Section titled “Basic Usage”// Set valueawait ctx.cache.put('user:123', user, '30m');
// Get valueconst user = await ctx.cache.get('user:123');
// Remember patternconst data = await ctx.cache.remember('key', '1h', async () => { return fetchExpensiveData();});
// Deleteawait ctx.cache.forget('user:123');Drivers
Section titled “Drivers”Memory (Development)
Section titled “Memory (Development)”cachePlugin({ driver: 'memory', config: { maxSize: 1000 },})Redis (Production)
Section titled “Redis (Production)”cachePlugin({ driver: 'redis', config: { url: process.env.REDIS_URL },})Tag-Based Invalidation
Section titled “Tag-Based Invalidation”// Set with tagsawait ctx.cache.tags(['users']).put('user:123', user);await ctx.cache.tags(['users']).put('user:456', user);
// Flush all taggedawait ctx.cache.tags(['users']).flush();Next Steps
Section titled “Next Steps”- Queue - Background jobs
- Ecosystem Overview - All packages