cache-manager is a Node.js caching module that provides a uniform API for multiple cache backends (in-memory, Redis, memcached, etc.). In NestJS, it serves as the foundation for the CacheModule abstraction.
NestJS integration
cache-manager-redis-storeis the Redis adapter, providing theredisStoreobject passed toCacheModule.register().- The
Cachetype (imported fromcache-manager) is used to type the injectedCACHE_MANAGERtoken. - Provides
get(key),set(key, value, { ttl }),del(key), andreset()methods.
Install
npm install cache-manager @types/cache-manager
npm install cache-manager-redis-store
npm install --save-dev @types/cache-manager-redis-storeTradeoffs vs. direct ioredis
cache-manager simplifies caching by providing a backend-agnostic API and working with NestJS decorators. However, it abstracts away Redis-specific features (pub/sub, pipelines, key scanning, cluster config). For advanced Redis usage, direct ioredis integration is preferable.