9

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
  • 1,095
  • 3
  • 15
  • 30

2 Answers2

6

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

Community
  • 1
  • 1
  • 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. – Sunil Sharma Jan 06 '16 at 11:47
  • 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) – Adam Link Aug 11 '16 at 21:54
  • 1
    You can use hooks for invalidation now... http://docs.sequelizejs.com/manual/tutorial/hooks.html – decoder7283 Jul 01 '17 at 23:23
5

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.

Idan Gozlan
  • 2,631
  • 2
  • 24
  • 43