sequelize-use-cache

2.0.1 • Public • Published

Sequelize-Use-Cache

caching sequelize result using redis

https://www.npmjs.com/package/sequelize-use-cache

Installation

npm install --save redis # prerequisite
npm install --save sequelize-use-cache

Usage

Usable methods

All select queries

parameter

model.findOne({
  // ...options,
  cache: true, // use cache or not, boolean
  expire: 10, // expire time(seconds), integer
})

Example

import Sequelize from 'sequelize'
import Redis from 'redis'
import useCache from 'sequelize-use-cache'
 
const redis = Redis.createClient()
const sequelize = new Sequelize()
 
// import models
sequelize.define('projects', {
  title: Sequelize.TEXT,
  description: Sequelize.TEXT,
})
 
useCache(sequelize, redis)
 
const { projects } = sequelize.models
 
projects.findAll({
  cache: true,
  expire: 5,
})
console.log(sequelize.cacheHit) // false
 
projects.findAll({
  cache: true,
  expire: 5,
})
console.log(sequelize.cacheHit) // true

License

MIT

reference

Package Sidebar

Install

npm i sequelize-use-cache

Weekly Downloads

4

Version

2.0.1

License

MIT

Unpacked Size

24.4 kB

Total Files

6

Last publish

Collaborators

  • haracejacob