Skip to content

forkkit/egg-lru

 
 

Repository files navigation

egg-lru

NPM version appveyor build status build status Test coverage Known Vulnerabilities npm download

egg lru-cache plugin

Install

$ npm i egg-lru --save

Configuration

// {app_root}/config/plugin.js
exports.lru = {
  enable: true,
  package: 'egg-lru',
};

see config/config.default.js for more detail.

Simple lru instance

// {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');

Multiple lru instance

// {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.

Questions & Suggestions

Please open an issue here.

License

MIT

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%