node-caches

2.0.0 • Public • Published

node-cache

node cache provider using redis, memcache, lru, mysql, file

Install

npm i node-caches --save

you need to install some dependencies for provider.

  • Mysql
  npm i sequelize mysql2 --save
  • Memcache
  npm i memcache-plus sequelize mysql2 --save
  • File
  npm i cacache --save 
  • Redis
  npm i ioredis --save  
  • LRU
  npm i lru-cache --save
  • Mongodb
npm i mongoose --save

Setup

 
import { config } from 'node-caches'
 

mysql

mysql = config({
  store: 'mysql',
  options: {
    database: 'ncache',
    username: 'root',
    password: 'root123456',
    host: 'localhost'
  }
})
 

options parameters will be passed to http://docs.sequelizejs.com/class/lib/sequelize.js~Sequelize.html#instance-constructor-constructor

memcache

  mem = config({
    store: 'memcache',
    options: {
      hosts: ['127.0.0.1:11211'],
      mysql: {
        database: 'ncache',
        username: 'root',
        password: 'root123456',
        host: 'localhost'
      }
    }
  })
 

options parameters will be passed to https://github.com/victorquinn/memcache-plus/blob/master/docs/initialization.md#options

options.mysql parameters will be passed to http://docs.sequelizejs.com/class/lib/sequelize.js~Sequelize.html#instance-constructor-constructor

file

  file = config({
    store: 'file',
    options: {
      path: path.resolve(__dirname, '.cache')
    }
  })

redis

  redis = config({
    store: 'redis',
    options: {
      port: 6379,
      host: '127.0.0.1'
    }
  })

options parameters will be passed to https://github.com/luin/ioredis/blob/master/API.md#new_Redis_new

lru

  lru = config({
    store: 'lru',
    options: {
      max: 500,
      maxAge: 1000 * 60 * 60
    }
  })

options parameters will be passed to https://github.com/isaacs/node-lru-cache#options

mongodb

  mongodb = config({
    store: 'mongodb',
    options: {
      url: 'mongodb://localhost:27017'
    }
  })

implements ICache API

export interface ICache {
  readFunction,
  writeFunction,
  deleteFunction,
  searchFunction,
  cleanFunction
}

Also see the API Documentation

LICENSE

Copyright (c) Terry Cai. Licensed under the MIT license.

Dependencies (0)

    Dev Dependencies (20)

    Package Sidebar

    Install

    npm i node-caches

    Weekly Downloads

    0

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    36 kB

    Total Files

    11

    Last publish

    Collaborators

    • icai