Performance: CacheModule setup
This affects server response time and reduces repeated data processing by storing results temporarily.
import { CacheModule } from '@nestjs/common'; import * as redisStore from 'cache-manager-redis-store'; @Module({ imports: [ CacheModule.register({ store: redisStore, host: 'localhost', port: 6379, ttl: 60, }), ], }) export class AppModule {}
import { CacheModule } from '@nestjs/common'; @Module({ imports: [CacheModule.register()], }) export class AppModule {}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Default CacheModule (in-memory, no TTL) | N/A | N/A | N/A | [!] OK |
| CacheModule with Redis store and TTL | N/A | N/A | N/A | [OK] Good |
CacheModule in a NestJS application?register to configure options like ttl.forRoot, setup, or init are not used by CacheModule.import { CacheModule, Module } from '@nestjs/common';
@Module({
imports: [CacheModule.register({ ttl: 10 })],
})
export class AppModule {}
What will be the effect of the ttl: 10 option?import { CacheModule, Module } from '@nestjs/common';
@Module({
imports: [CacheModule.register({ ttl: '20' })],
})
export class AppModule {}@UseInterceptors(CacheInterceptor) on the controller enables caching for all its routes.@Cacheable() or @Cache() decorators exist in NestJS core; manual caching is possible but not automatic.Pass the test and this pattern moves unknown