mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-13 05:20:25 +00:00
cache-manager: add store to Cache (#42554)
This commit is contained in:
@@ -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) => {
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Vendored
+26
-2
@@ -56,7 +56,31 @@ export interface Cache {
|
||||
set<T>(key: string, value: T, ttl: number): Promise<any>;
|
||||
set<T>(key: string, value: T, options: CachingConfig, callback: (error: any) => void): void;
|
||||
set<T>(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<T>(...keys: string[], work: (callback: (error: any, result: T) => void) => void, options: CachingConfig, callback: (error: any, result: T) => void): void
|
||||
// wrap<T>(...keys: string[], work: (callback: (error: any, result: T) => void) => void, callback: (error: any, result: T) => void): void
|
||||
// wrap<T>(...keys: string[], work: (callback: (error: any, result: T) => void) => void, options: CachingConfig): void
|
||||
// wrap<T>(...keys: string[], work: (callback: (error: any, result: T) => void) => void): Promise<any>;
|
||||
wrap<T>(...args: WrapArgsType<T>[]): Promise<any>;
|
||||
|
||||
get<T>(key: string, callback: (error: any, result: T) => void): void;
|
||||
get<T>(key: string): Promise<any>;
|
||||
|
||||
del(key: string, callback: (error: any) => void): void;
|
||||
del(key: string): Promise<any>;
|
||||
|
||||
store: Store;
|
||||
}
|
||||
|
||||
export interface MultiCache {
|
||||
set<T>(key: string, value: T, options: CachingConfig): Promise<any>;
|
||||
set<T>(key: string, value: T, ttl: number): Promise<any>;
|
||||
set<T>(key: string, value: T, options: CachingConfig, callback: (error: any) => void): void;
|
||||
set<T>(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;
|
||||
|
||||
Reference in New Issue
Block a user