@@ -17,6 +17,7 @@ import {
1717 CACHE_MANAGER ,
1818 CACHE_TTL_METADATA ,
1919} from '../cache.constants' ;
20+ import { CacheKeyFactory , CacheTTLFactory } from '../decorators' ;
2021
2122/**
2223 * @see [Caching](https://docs.nestjs.com/techniques/caching)
@@ -41,7 +42,7 @@ export class CacheInterceptor implements NestInterceptor {
4142 next : CallHandler ,
4243 ) : Promise < Observable < any > > {
4344 const key = this . trackBy ( context ) ;
44- const ttlValueOrFactory =
45+ const ttlValueOrFactory : number | CacheTTLFactory | null =
4546 this . reflector . get ( CACHE_TTL_METADATA , context . getHandler ( ) ) ??
4647 this . reflector . get ( CACHE_TTL_METADATA , context . getClass ( ) ) ??
4748 null ;
@@ -90,13 +91,13 @@ export class CacheInterceptor implements NestInterceptor {
9091 protected trackBy ( context : ExecutionContext ) : string | undefined {
9192 const httpAdapter = this . httpAdapterHost . httpAdapter ;
9293 const isHttpApp = httpAdapter && ! ! httpAdapter . getRequestMethod ;
93- const cacheMetadata = this . reflector . get (
94- CACHE_KEY_METADATA ,
95- context . getHandler ( ) ,
96- ) ;
94+ const cacheMetadataOrFactory : string | CacheKeyFactory | null =
95+ this . reflector . get ( CACHE_KEY_METADATA , context . getHandler ( ) ) ?? null ;
9796
98- if ( ! isHttpApp || cacheMetadata ) {
99- return cacheMetadata ;
97+ if ( ! isHttpApp || cacheMetadataOrFactory ) {
98+ return isFunction ( cacheMetadataOrFactory )
99+ ? cacheMetadataOrFactory ( context )
100+ : cacheMetadataOrFactory ;
100101 }
101102
102103 const request = context . getArgByIndex ( 0 ) ;
0 commit comments