Nest - High Performance Layer 1 / Layer 2 Caching with Keyv Storage for NestJS (@cacheable-manager)
npm install @leomongeg/nestjs-cacheable-manager
A progressive Node.js framework for building efficient and scalable server-side applications.
nestjs-cacheable-manager module for Nest
is a high performance layer 1 / layer 2 caching engine that is focused on distributed caching based on cacheable
This package was created using as base the @nestjs/cache-manager, since
@nestjs/cache-manager uses cache-manager and doesn't support the
cacheable layer 1 / layer 2 caching engine.
This package removed the cache-manager and uses directly the cacheable
instead to support layer 1 / layer 2 caches.
The interfaces and usage are the same as @nestjs/cache-manager it works the same but using directly cacheable
``bash`
$ npm i --save @leomongeg/nestjs-cacheable-manager cacheable
`typescript
import { CacheableModule } from '@leomongeg/nestjs-cacheable-manager';
import { CacheableMemory } from 'cacheable';
import KeyvRedis from '@keyv/redis';
import { Keyv } from 'keyv';
@Module({
imports: [
CacheableModule.registerAsync({
useFactory: async () => {
return {
primary: new Keyv({ store: new CacheableMemory({ ttl: 60000, lruSize: 5000 }) }),
secondary: new KeyvRedis('redis://localhost:6379')
}
}
}),
],
controllers: [MyController],
})
export class MyModuleModule {}
`
`typescript
import { Cacheable } from 'cacheable';
import { CACHEABLE_MANAGER } from '@leomongeg/nestjs-cacheable-manager';
@Injectable()
export class MyProvider {
constructor(
@Inject(CACHEABLE_MANAGER) private readonly cache: Cacheable,
) {}
async getSomething(request: RequestDto){
const val = await this.cache.get('key');
}
async storeSomething(request: RequestDto){
await this.cache.set('key', request.userId);
}
async deleteSomething(request:RequestDto){
await this.cache.delete('key');
}
}
``
For more details about cache layer 1 and layer 2 please reach out the cacheable documentation.
Nest is an MIT-licensed open source project.
- Author - Leonardo Monge García
This package is based on Kamil Myśliwiec @nestjs/cache-manager
Nest is MIT licensed.