egg lru-cache plugin
$ npm i egg-lru --save
// {app_root}/config/plugin.js
exports.lru = {
enable: true,
package: 'egg-lru',
};
see config/config.default.js for more detail.
// {app_root}/config/config.default.js
exports.lru = {
client: {
// all lru cache config available here
max: 1000,
maxAge: 1000 * 60 * 60, // 60 min cache
},
// load into app, default is open
app: true,
// load into agent, default is close
agent: false,
};
Usage:
// you can access to simple lru instance by using app.lru
app.lru.set('test', 'aaa') ;
app.lru.get('test');
// {app_root}/config/config.default.js
exports.lru = {
clients: {
long: {
max: 1000,
maxAge: 1000 * 60 * 60, // 60 min cache
},
moment: {
max: 1000,
maxAge: 1000, // 1 second cache
},
},
// load into app, default is open
app: true,
// load into agent, default is close
agent: false,
};
Usage:
const long = app.lru.get('long');
long.set('test', 'aaa') ;
long.get('test');
const moment = app.lru.get('moment');
moment.set('test', 'aaa') ;
moment.get('test');
see config/config.default.js for more detail.
Please open an issue here.