Registry / storage / nest-cache-manager

nest-cache-manager

JSON →
library1.2.4jsnpmunverified

A NestJS-specific caching library that integrates Redis for response caching. Current stable version is 1.2.4 with a monthly release cadence. It provides a RedisService and a @Cache decorator for controller methods. Unlike generic cache-manager, this package is tailored for NestJS decorators and environment-based configuration (REDIS_HOST, REDIS_PORT). It includes TypeScript types and works with NestJS modules.

npm install nest-cache-manager
INSTALL
IMPORT
SIG · NEST-CACHE-MANAGER
N
nest-cache-manager
storagejavascriptv1.2.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RedisService
✓ import { RedisService } from 'nest-cache-manager'
✗ const RedisService = require('nest-cache-manager').RedisService
ESM-only; CJS require may work but ESM is recommended.
Cache
✓ import { Cache } from 'nest-cache-manager'
✗ import { CacheDecorator } from 'nest-cache-manager'
Named export, not default. The decorator is used directly.
RedisService
✓ import { RedisService } from 'nest-cache-manager'
✗ import RedisService from 'nest-cache-manager'
RedisService is a named export, not default.

Shows how to set up RedisService in a module and use @Cache decorator on a controller method.

import { Module } from '@nestjs/common'; import { RedisService } from 'nest-cache-manager'; @Module({ providers: [RedisService], exports: [RedisService], }) export class CacheModule {} // In a controller: import { Cache } from 'nest-cache-manager'; import { Controller, Get } from '@nestjs/common'; @Controller('items') export class ItemsController { @Get() @Cache('itemsList', 3600) async findAll() { // Business logic return ['item1', 'item2']; } }
Debug
Known issues
gotchaThe @Cache decorator expects exactly two arguments: cacheKey (string) and ttl (number in seconds). Omitting or using wrong types will result in runtime errors.
fix
Always provide both arguments: @Cache('myKey', 60).
affects: >=1.0.0
gotchaEnvironment variables REDIS_HOST and REDIS_PORT are read at module initialization. If not set, defaults (localhost:6379) are used.
fix
Set REDIS_HOST and REDIS_PORT in your .env or process.env.
affects: >=1.0.0
gotchaThe package does not handle Redis connection errors. If Redis is unreachable, the server may crash.
fix
Wrap the RedisService in a custom module with error handling or health checks.
affects: >=1.0.0
deprecatedNo known deprecations.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'nest-cache-manager' or its corresponding type declarations.
Package not installed or not included in tsconfig.json paths.
fix
Run 'npm install nest-cache-manager' and ensure your tsconfig.json includes node_modules types.
The @Cache decorator must be used within a NestJS context.
Attempting to use the decorator outside of a NestJS controller class.
fix
Apply @Cache only to methods in classes decorated with @Controller().
Upgrade
Version history
1.2.4latest on npm
Audit
Dependencies
@nestjs/commonrequiredDecorators and NestJS module basics
redisrequiredRedis client used for caching
Agent activity
17 hits · last 30 days
node
16
Resources
nest-cache-manager — npm install nest-cache-manager · libregistry