@@ -23,7 +23,7 @@ export const buildCacheOptionsFromProvider = (provider: CacheProvider | any): Ca
2323 }
2424}
2525export const createCacheManager = ( options : CacheOptions ) : Cache => {
26- const { store, max, ttl = 60 , host = 'localhost' , port, auth_pass, db, ...rest } = options ;
26+ const { store, max, ttl = 60 , host = 'localhost' , port, auth_pass, db, prefix , ...rest } = options ;
2727 switch ( store ) {
2828 case 'none' :
2929 return cacheManager . caching ( { store : 'none' , max, ttl} ) ;
@@ -52,11 +52,11 @@ export class CMCache {
5252 providerOptions : CacheOptions ;
5353 logger ! : Logger ;
5454
55- constructor ( cache : Cache , providerOptions : CacheOptions , defaultCache : boolean , ttls : Partial < StrongTTLConfig > , logger : Logger , prefix ?: string ) {
55+ constructor ( cache : Cache , providerOptions : CacheOptions , defaultCache : boolean , ttls : Partial < StrongTTLConfig > , logger : Logger ) {
5656 this . cache = cache ;
5757 this . providerOptions = providerOptions
58- this . prefix = prefix ;
5958 this . isDefaultCache = defaultCache ;
59+ this . prefix = this . providerOptions . prefix ?? '' ;
6060
6161 this . setLogger ( logger ) ;
6262
@@ -176,22 +176,23 @@ export class CMCache {
176176 }
177177
178178 del ( key : string ) : Promise < any > {
179- return this . cache . del ( key ) ;
179+ return this . cache . del ( ` ${ this . prefix } ${ key } ` ) ;
180180 }
181181
182182 get < T > ( key : string ) : Promise < T | undefined > {
183- return this . cache . get ( key ) ;
183+ return this . cache . get ( ` ${ this . prefix } ${ key } ` ) ;
184184 }
185185
186186 reset ( ) : Promise < void > {
187187 return this . cache . reset ( ) ;
188188 }
189189
190190 set < T > ( key : string , value : T , options ?: CachingConfig ) : Promise < T > {
191- return this . cache . set ( key , value , options ) ;
191+ return this . cache . set ( ` ${ this . prefix } ${ key } ` , value , options ) ;
192192 }
193193
194194 wrap < T > ( ...args : WrapArgsType < T > [ ] ) : Promise < T > {
195+ args [ 0 ] = `${ this . prefix } ${ args [ 0 ] } ` ;
195196 return this . cache . wrap ( ...args ) ;
196197 }
197198
0 commit comments