diff --git a/types/cache-manager/cache-manager-tests.ts b/types/cache-manager/cache-manager-tests.ts index 47ca62c020..827743de58 100644 --- a/types/cache-manager/cache-manager-tests.ts +++ b/types/cache-manager/cache-manager-tests.ts @@ -48,3 +48,26 @@ memoryCache.wrap<{ id: number, name: string }>(key, (cb: any) => { }); }); + +memoryCache.store.keys().then((result) => { + + //console.log(result); +}); + +const multiCache = cacheManager.multiCaching([memoryCache]); + +multiCache.set('foo', 'bar', { ttl: ttl }, (err) => { + + if (err) { + throw err; + } + + multiCache.get('foo', (err, result) => { + + // console.log(result); + + multiCache.del('foo', (err) => { + }); + + }); +}); diff --git a/types/cache-manager/index.d.ts b/types/cache-manager/index.d.ts index cd86e851bd..dc0b3b8eb7 100644 --- a/types/cache-manager/index.d.ts +++ b/types/cache-manager/index.d.ts @@ -56,7 +56,31 @@ export interface Cache { set(key: string, value: T, ttl: number): Promise; set(key: string, value: T, options: CachingConfig, callback: (error: any) => void): void; set(key: string, value: T, ttl: number, callback: (error: any) => void): void; - + + // Because the library accepts multiple keys as arguments but not as an array and rather as individual parameters + // of the function, the type definition had to be changed to this rather than specific ones + // actual definitions would looks like this (impossible in typescript): + // wrap(...keys: string[], work: (callback: (error: any, result: T) => void) => void, options: CachingConfig, callback: (error: any, result: T) => void): void + // wrap(...keys: string[], work: (callback: (error: any, result: T) => void) => void, callback: (error: any, result: T) => void): void + // wrap(...keys: string[], work: (callback: (error: any, result: T) => void) => void, options: CachingConfig): void + // wrap(...keys: string[], work: (callback: (error: any, result: T) => void) => void): Promise; + wrap(...args: WrapArgsType[]): Promise; + + get(key: string, callback: (error: any, result: T) => void): void; + get(key: string): Promise; + + del(key: string, callback: (error: any) => void): void; + del(key: string): Promise; + + store: Store; +} + +export interface MultiCache { + set(key: string, value: T, options: CachingConfig): Promise; + set(key: string, value: T, ttl: number): Promise; + set(key: string, value: T, options: CachingConfig, callback: (error: any) => void): void; + set(key: string, value: T, ttl: number, callback: (error: any) => void): void; + // Because the library accepts multiple keys as arguments but not as an array and rather as individual parameters // of the function, the type definition had to be changed to this rather than specific ones // actual definitions would looks like this (impossible in typescript): @@ -74,4 +98,4 @@ export interface Cache { } export function caching(IConfig: StoreConfig & CacheOptions): Cache; -export function multiCaching(Caches: Cache[], options?: CacheOptions): Cache; +export function multiCaching(Caches: Cache[], options?: CacheOptions): MultiCache;