removing I from Interface-Names

This commit is contained in:
Simon Gausmann
2015-10-21 20:45:16 +02:00
parent d1b97507ac
commit 1fbadc0733
2 changed files with 21 additions and 22 deletions

View File

@@ -2,10 +2,10 @@
import * as cacheManager from 'cache-manager'
const memoryCache = cacheManager.caching({store: 'memory', max: 100, ttl: 10/*seconds*/});
const memoryCache = cacheManager.caching({ store: 'memory', max: 100, ttl: 10/*seconds*/ });
const ttl = 5;
memoryCache.set('foo', 'bar', {ttl: ttl}, (err) => {
memoryCache.set('foo', 'bar', { ttl: ttl }, (err) => {
if (err) {
throw err;
@@ -21,25 +21,25 @@ memoryCache.set('foo', 'bar', {ttl: ttl}, (err) => {
});
});
function getUser(id:number, cb:Function) {
function getUser(id: number, cb: Function) {
cb(null, {id: id, name: 'Bob'});
cb(null, { id: id, name: 'Bob' });
}
const userId = 123;
const key = 'user_' + userId;
// Note: ttl is optional in wrap()
memoryCache.wrap<{id: number, name: string}>(key, (cb) => {
memoryCache.wrap<{ id: number, name: string }>(key, (cb) => {
getUser(userId, cb);
}, {ttl: ttl}, (err, user) => {
}, { ttl: ttl }, (err, user) => {
//console.log(user);
// Second time fetches user from memoryCache
memoryCache.wrap<{id: number, name: string}>(key, (cb)=> {
memoryCache.wrap<{ id: number, name: string }>(key, (cb) => {
getUser(userId, cb);
@@ -48,4 +48,4 @@ memoryCache.wrap<{id: number, name: string}>(key, (cb) => {
//console.log(user);
});
});
});

View File

@@ -5,32 +5,31 @@
declare module 'cache-manager' {
interface ICachingConfig {
interface CachingConfig {
ttl: number;
}
interface IStoreConfig extends ICachingConfig {
store:string;
interface StoreConfig extends CachingConfig {
store: string;
max?: number;
isCacheableValue?:(value:any)=>boolean;
isCacheableValue?: (value: any) => boolean;
}
interface ICache {
set<T>(key:string, value:T, options:ICachingConfig, callback?:(error:any)=>void):void;
set<T>(key:string, value:T, ttl:number, callback?:(error:any)=>void):void;
interface Cache {
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;
wrap<T>(key:string, wrapper:(callback:(error:any, result:T)=>void)=>void, options:ICachingConfig, callback:(error:any, result:T)=>void):void;
wrap<T>(key:string, wrapper:(callback:(error:any, result:T)=>void)=>void, callback:(error:any, result:T)=>void):void;
wrap<T>(key: string, wrapper: (callback: (error: any, result: T) => void) => void, options: CachingConfig, callback: (error: any, result: T) => void): void;
wrap<T>(key: string, wrapper: (callback: (error: any, result: T) => void) => void, callback: (error: any, result: T) => void): void;
get<T>(key:string, callback:(error:any, result:T)=>void):void;
get<T>(key: string, callback: (error: any, result: T) => void): void;
del(key:string, callback?:(error:any)=>void):void;
del(key: string, callback?: (error: any) => void): void;
}
module cacheManager {
function caching(ICongig:IStoreConfig):ICache;
function multiCaching(Caches:ICache[]):ICache;
function caching(ICongig: StoreConfig): Cache;
function multiCaching(Caches: Cache[]): Cache;
}
export = cacheManager;