0
0
NestJSframework~10 mins

Why caching reduces response latency in NestJS - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the caching module in a NestJS app.

NestJS
import { [1] } from '@nestjs/cache-manager';
Drag options to blanks, or click blank then click option'
AConfigModule
BLoggerModule
CHttpModule
DCacheModule
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated modules like HttpModule or LoggerModule.
2fill in blank
medium

Complete the code to register the CacheModule globally in the app module.

NestJS
@Module({
  imports: [[1].register()],
})
export class AppModule {}
Drag options to blanks, or click blank then click option'
ACacheModule
BHttpModule
CConfigModule
DLoggerModule
Attempts:
3 left
💡 Hint
Common Mistakes
Registering the wrong module or forgetting to call register().
3fill in blank
hard

Fix the error in the method decorator to enable caching for a controller route.

NestJS
@[1]
@Get('data')
getData() {
  return this.service.getData();
}
Drag options to blanks, or click blank then click option'
ACacheable()
BCacheInterceptor()
CCacheable
DCacheKey()
Attempts:
3 left
💡 Hint
Common Mistakes
Using decorators that do not exist or require arguments.
4fill in blank
hard

Fill both blanks to inject the cache manager and use it to set a cache value.

NestJS
constructor(@Inject([1]) private cacheManager: [2]) {}

async cacheData(key: string, value: any) {
  await this.cacheManager.set(key, value);
}
Drag options to blanks, or click blank then click option'
ACACHE_MANAGER
BCacheManager
CCache
DCacheStore
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong injection tokens or types that don't exist.
5fill in blank
hard

Fill the blank to create a cache interceptor and apply it to a controller method.

NestJS
@UseInterceptors([1])
@Get('info')
async getInfo() {
  const data = await this.service.fetchInfo();
  return data;
}
Drag options to blanks, or click blank then click option'
ACacheInterceptor
BCacheModule
CCacheManager
DCacheService
Attempts:
3 left
💡 Hint
Common Mistakes
Using modules or services instead of the interceptor.