Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement caching mechanism in Sequelize ORM npm -- node.js

I am writing REST APIs in Node.js with Sequelize as ORM npm, to manage my data models.

I am concerned about my APIs performance because there are many clients, will be using same API, so I want to implement caching mechanism in Sequelize ORM.

Would it be possible with Sequelize ORM ? if yes How ?

like image 407
Sunil Sharma Avatar asked Jan 06 '16 07:01

Sunil Sharma


People also ask

What is Sequelize ORM in node JS?

Sequelize is an Object Relational Mapper for Node. js. Sequelize lets us connect to a database and perform operations without writing raw SQL queries. It abstracts SQL queries and makes it easier to interact with database models as objects.


2 Answers

You can use caching layers like Redis or Memcached to store your results, if you have big ammounts of data. Here is a comparison between these two Memcached vs. Redis?. Also there is sequelize-redis-cache npm package you can use https://github.com/rfink/sequelize-redis-cache

like image 195
Tudor Crisan Avatar answered Sep 21 '22 12:09

Tudor Crisan


If you are using Sequelize 4, check out that module:

https://github.com/idangozlan/sequelize-redis

It's a full solution for caching + invalidating cache easily, and as much as I know it's the only Sequelize 4 caching module (right now).

Disclaimer: I'm the author of that module and I'm using that on production for daily traffic of 1m unique users.

like image 44
Idan Gozlan Avatar answered Sep 20 '22 12:09

Idan Gozlan