Performance: Cache interceptor
MEDIUM IMPACT
This affects server response time and client perceived load speed by reducing repeated processing and data fetching.
import { CacheInterceptor, ExecutionContext, Injectable } from '@nestjs/common'; @Injectable() export class CustomCacheInterceptor extends CacheInterceptor { trackBy(context: ExecutionContext): string | undefined { const request = context.switchToHttp().getRequest(); return request.url; // Cache key based on URL } }
import { Injectable, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common'; import { Observable } from 'rxjs'; @Injectable() export class NoCacheInterceptor implements NestInterceptor { intercept(context: ExecutionContext, next: CallHandler): Observable<any> { // Always process request without caching return next.handle(); } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No cache interceptor | N/A (server-side) | N/A | N/A | [X] Bad |
| Cache interceptor with URL key | N/A (server-side) | N/A | N/A | [OK] Good |