@nestjs-redisx/cache
v1.0.3
Published
Advanced caching plugin for NestJS RedisX with L1+L2, anti-stampede, SWR, and tag invalidation
Maintainers
Readme
@nestjs-redisx/cache
Two-tier caching plugin for NestJS RedisX. L1 in-memory + L2 Redis with anti-stampede protection, stale-while-revalidate (SWR), tag-based invalidation, and declarative @Cached decorator.
Installation
npm install @nestjs-redisx/core @nestjs-redisx/cache ioredisQuick Example
import { RedisModule } from '@nestjs-redisx/core';
import { CachePlugin, Cached } from '@nestjs-redisx/cache';
@Module({
imports: [
RedisModule.forRoot({
clients: { host: 'localhost', port: 6379 },
plugins: [new CachePlugin({ l1: { maxSize: 1000 }, l2: { defaultTtl: 3600 } })],
}),
],
})
export class AppModule {}
@Injectable()
export class UserService {
@Cached({ key: 'user:{0}', ttl: 300, tags: ['users'] })
async getUser(id: string) {
return this.repo.findById(id);
}
}Documentation
Full documentation: nestjs-redisx.dev/en/reference/cache/
License
MIT
