I would like to know how can I use a cache with Sequelize?
I look at the different package ( sequelize-transparent-cache , ...), but the cache use with the model.
How can I use a cache with sequelize.query('SELECT * FROM Books')
and not model?
For example, using Cache-Aside pattern .
The pseudo code is as follows:
async function findAllBooks() {
let books = await cache.get('books');
if(!books) {
books = await sequelize.query('SELECT * FROM Books');
await cache.set('books', books);
}
return books;
}
The sequelize-transparent-cache
package uses the same pattern for findByPk()
method, see the source code: https://github.com/DanielHreben/sequelize-transparent-cache/blob/master/packages/sequelize-transparent-cache/src/methods/class.js#L14
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.