zkt-loader
cache data resource with smart auto-refresh and lock.
Usage
new ZKTLoader(name, loadFunction, options)
const ZKTLoader = ;const loader = 'user' { return db;} useRedis: true redisOptions: 'redis://127.0.0.1:6379' //options passed to ioredis; //... router; //...
options
//use redis? if not, use in-memory cache provided by node-cache useRedis: false //parameter passed to new IORedis() redisOptions: processenvREDIS_URL //use existing ioredis instance? redisInstance: null //default expiration seconds //if you request data after this time, zkt-loader will return cached //data immediately, then request real data to update cache in background ttl: 30 //prefix for every key keyPrefix: 'zktLoader'
cacheable decorator
require('zkt-loader').cacheable(name, options)(loadFunction)
example:
const cacheable = ; { console; return 'foo' + id;}getName = getName; ;;