Cache
Cache methods results using appolo-cache
with optional redis store
#
Installation#
Optionskey | Description | Type | Default |
---|---|---|---|
id | cacheProvider injector id | string | cacheProvider |
connection | redis connection string | string | `` |
memory | true to use memory store | boolean | true |
db | true to use redis store | boolean | false |
maxSize | max memory store items | number | 1000 |
keyPrefix | redis prefix key | string | c |
all option are optional and will be added as defaults to cache options in config/modules/all.ts
#
Cache Optionskey | Description | Type | Default |
---|---|---|---|
id | custom cache id | string | className_methodName |
maxSize | max cache size | number | 1000 |
maxAge | set maximum age in ms of all cache items | number | unlimited |
clone | clone the cache result | boolean | false |
interval | set cache refresh interval in ms | number | undefined |
resolver | function to get the cache key by default the first argument will be used as the cache key. | function | undefined |
multi | if no resolver defined use all the arguments as key else use the first argument as key | boolean | false |
peek | use peek method instead of get | boolean | false |
refresh | refresh cache on half maxAge expire | boolean | false |
keyPrefix | redis prefix key | string | c |
memory | true to use memory store | boolean | true |
db | true to use redis store | boolean | false |
dbMaxAge | set maximum age in ms of all cache items in db if not defined maxAge will be used | number | unlimited |
cacheNull | cache null results | boolean | false |
#
Usage#
CacheProvider#
createCachecreateCache(options: ICacheOptions, valueFn: Function, scope?: any)
#
create new cache wrapper
- options - cache options
- valueFn - value function will be called to get the value
- scope - scope of the value function
#
getCacheByIdgetCacheById(id:string):Cache
#
return cache wrapper by id
#
Cachecache wrapper instance
#
getget<T>(...args: any[]): Promise<T> | T
#
get value from cache if not found the value fn will be called
#
cachecache:Cache
#
getter return appolo-cache​
instance