Turbo is a caching layer that is eventually consistent for FAUW (Frequent access, unfrequent writes) objects.
npm install sequelize-turbo --save
yarn add --save
Whenever you create Sequelize objects in your code, wrap them as follow:
const Turbo = require('sequelize-turbo')
const User = Turbo(
sequelize.define('User', {
...config
})
)
export default User
That's it! Turbo uses RAM to cache objects. However, is a distributed environment, using Redis is much more efficient.
Turbo adds decoratos on top of the usual sequelize functions find
, update
, destroy
and insert
. Using a dependency cache, Turbo can figure out when to
invalidate objects and when to cache them.
Turbo guarantees freshness of the objects, you will never get outdated objects.
Set the following environment variable to debug Turbo: DEBUG=turbo:*