Backend_DevOps

NestJS, Cache-Manager v5 사용시 문제 해결법

2025-12-271 min read

NestJS, Cache-Manager v5 사용시 문제 해결법

문제

공식문서에 나온대로 하면 this.cacheManager.get is not a function 발생

원인

cache-managerv5로 올라가면서 사용법이 아예 바뀜..

해결

import { registerAs } from '@nestjs/config'
import { CACHE_CONFIG_KEY } from '../constants/index.js'
import { redisStore } from 'cache-manager-redis-store'
import { CacheConfigSchema } from './config.zod.js'

export const cacheConfig = registerAs(CACHE_CONFIG_KEY, async () =>
	CacheConfigSchema.parseAsync({
		host: process.env.CACHE_HOST,
		port: Number(process.env.CACHE_PORT),
		ttl: Number(process.env.CACHE_TTL),
		store: redisStore,
	}),
)

@Module({
  providers: [
    {
      provide: CACHE_MANAGER,
      inject: [cacheConfig.KEY],
      useFactory: ({ store, ...config }: ConfigType<typeof cacheConfig>) =>
        caching(store, config),
    },
  ],
})
export class AppCacheModule
Share

Related Articles

Comments

이 블로그는 제가 알고 있는 것들을 잊지 않기 위해 기록하는 공간입니다.
직접 작성한 글도 있고, AI의 도움을 받아 정리한 글도 있습니다.
정확하지 않은 내용이 있을 수 있으니 참고용으로 봐주세요.

© 2026 Seogyu Kim