@@ -5,7 +5,7 @@ import type { Environment } from '#/types/index'
55
66export interface ICacheService {
77 get ( key : string ) : Promise < { } | null >
8- put ( key : string , value : string ) : Promise < void >
8+ put ( key : string , value : string , ttl ?: number ) : Promise < void >
99}
1010
1111export class CacheService implements ICacheService {
@@ -52,16 +52,22 @@ export class CacheService implements ICacheService {
5252 return this . #env. EFP_DATA_CACHE . get ( key , 'json' )
5353 }
5454
55- async put ( key : string , value : string ) : Promise < void > {
55+ async put ( key : string , value : string , ttl = this . #env . CACHE_TTL ) : Promise < void > {
5656 if ( this . #cacheType === 'redis' ) {
5757 if ( ! this . #client) {
5858 this . #client = this . createRedisClient ( )
5959 }
60- await ( this . #client as RedisClientType ) . set ( key , value , {
61- EX : this . #env. CACHE_TTL
62- } as any )
60+ if ( ttl === 0 ) {
61+ await ( this . #client as RedisClientType ) . set ( key , value , { } as any )
62+ } else {
63+ await ( this . #client as RedisClientType ) . set ( key , value , {
64+ EX : ttl
65+ } as any )
66+ }
67+ } else if ( ttl === 0 ) {
68+ await this . #env. EFP_DATA_CACHE . put ( key , value , { } )
6369 } else {
64- await this . #env. EFP_DATA_CACHE . put ( key , value , { expirationTtl : this . #env . CACHE_TTL } )
70+ await this . #env. EFP_DATA_CACHE . put ( key , value , { expirationTtl : ttl } )
6571 }
6672 }
6773}
0 commit comments