egg-catbox

2.0.0 • Public • Published

egg-catbox

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Catbox plugin for egg framework.

Install

$ npm i egg-catbox --save

Usage

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

Configuration

// {app_root}/config/config.default.js
exports.catbox = {
};

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

Example

// {app_root}/app/service/user.js
const Service = require('egg').Service;
 
const segment = 'segment';
 
class UserService extends Service {
  async save(user, ttl) {
    const id = 'id';
    const key = { id, segment };
    await app.catbox.set(key, user, ttl);
  }
  async load(id) {
    const key = { id, segment };
    const result = await app.catbox.get(key);
    return result ? result.item : null;
  }
  async drop(id) {
    const key = { id, segment };
    await app.catbox.drop(key);
  }
}
 
module.exports = UserService;

Questions & Suggestions

Please open an issue here.

License

MIT

Package Sidebar

Install

npm i egg-catbox

Weekly Downloads

1

Version

2.0.0

License

MIT

Last publish

Collaborators

  • wsw0108