Caching in NestJS can be achieved through two distinct approaches: the built-in CacheModule with CacheInterceptor, or manual integration with Redis via ioredis.

Built-in approach (CacheModule)

NestJS provides a store-agnostic caching layer via @nestjs/common:

  • Import CacheModule.register() with a Redis store adapter (cache-manager-redis-store).
  • Use @UseInterceptors(CacheInterceptor) for automatic HTTP response caching on @Get() routes.
  • Customize per-endpoint with @CacheKey() and @CacheTTL().
  • Inject CACHE_MANAGER for manual get()/set()/del()/reset() operations.

Sources: How to add Redis cache to a NestJS app

Manual ioredis approach

For full control over Redis, build a custom service:

Sources: Using Redis Client in NestJS

Choosing an approach

FactorCacheModuleManual ioredis
BoilerplateLowMedium-high
Redis feature accessLimitedFull
Decorator supportYesNo
Backend portabilityYesNo
TestingBuilt-in mockingManual mocking
Production readinessGood for simple cachingGood for any Redis use case