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

14,282

Solution 1

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

Solution 2

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.

Share:
14,282
Sunil Sharma
Author by

Sunil Sharma

I am a very positive thinker and enthusiastic web developer, I always keen to learn new technologies, best programming practices. Well I am a Software Engineer with a particular interest in JavaScript and frameworks/libs runs over it, Java/J2EE. I also do lot of work in database schema designing, HTML, CSS and several other languages. I have been doing this professionally for 2.5 years. My blog site is on the way ..!! SOreadytohelp

Updated on July 25, 2022

Comments

  • Sunil Sharma
    Sunil Sharma almost 2 years

    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 ?

  • Sunil Sharma
    Sunil Sharma over 8 years
    I know there are lot of npm and other techniques available. But I am looking for without any other resource like Redis or Memcached. I dont want to waste my money by purchasing other instances for this purpose only.
  • Adam Link
    Adam Link almost 8 years
    Note that sequelize-redis-cache doesn't handle automatic invalidation when records are updated. As such, you either need to write invalidation logic or set short TTLs. @SunilSharma I'd suggest looking at these solutions. Your only other option is caching on disk via files, and that's slow compared to redis or memcached (both of which are free actually)
  • buycanna.io
    buycanna.io almost 7 years
    You can use hooks for invalidation now... docs.sequelizejs.com/manual/tutorial/hooks.html