sequelize-simple-cache
Advanced tools
Comparing version 1.0.0-beta.6 to 1.0.0-beta.7
{ | ||
"name": "sequelize-simple-cache", | ||
"version": "1.0.0-beta.6", | ||
"version": "1.0.0-beta.7", | ||
"description": "A simple, transparent, client-side, in-memory cache for Sequelize", | ||
@@ -49,5 +49,4 @@ "main": "src/SequelizeSimpleCache.js", | ||
"dependencies": { | ||
"bluebird": "^3.5.3", | ||
"md5": "^2.2.1" | ||
} | ||
} |
@@ -77,7 +77,7 @@ # sequelize-simple-cache | ||
// this is not good | ||
Model.findOne({ where: { startDate: { [Op.lte]: new Date() }, } }); | ||
Model.findAll({ where: { startDate: { [Op.lte]: new Date() }, } }); | ||
// you should do it this way | ||
Model.findOne({ where: { startDate: { [Op.lte]: fn('NOW') }, } }); | ||
Model.findAll({ where: { startDate: { [Op.lte]: fn('NOW') }, } }); | ||
// if you don't want a query to be cached, you may explicitly bypass the cache like this | ||
Model.noCache().findOne(...); | ||
Model.noCache().findAll(...); | ||
``` | ||
@@ -84,0 +84,0 @@ |
@@ -1,2 +0,1 @@ | ||
const Promise = require('bluebird'); | ||
const md5 = require('md5'); | ||
@@ -8,3 +7,3 @@ const { inspect } = require('util'); | ||
constructor(config = {}, options = {}) { | ||
this.defaults = { | ||
const defaults = { | ||
ttl: 60 * 60, // 1 hour | ||
@@ -14,3 +13,3 @@ methods: ['findById', 'findOne', 'findAll', 'findAndCountAll', 'count', 'min', 'max', 'sum'], | ||
this.config = Object.entries(config) | ||
.reduce((acc, [name, { ttl = this.defaults.ttl, methods = this.defaults.methods }]) => ({ | ||
.reduce((acc, [name, { ttl = defaults.ttl, methods = defaults.methods }]) => ({ | ||
...acc, | ||
@@ -67,3 +66,3 @@ [name]: { ttl, methods }, | ||
} | ||
const fn = (...args) => { | ||
const fn = async (...args) => { | ||
const hash = SequelizeSimpleCache.hash({ name, prop, args }); | ||
@@ -77,3 +76,3 @@ const item = this.cache.get(hash); | ||
}); | ||
return Promise.resolve(data); // resolve from cache | ||
return data; // resolve from cache | ||
} | ||
@@ -87,3 +86,3 @@ } | ||
} | ||
return Promise.resolve(data); // resolve from database | ||
return data; // resolve from database | ||
}); | ||
@@ -90,0 +89,0 @@ }; |
@@ -357,5 +357,5 @@ const chai = require('chai'); | ||
sinon.stub(User, 'findOne').returns({ username: 'foo' }); // should be `resolves` | ||
expect(() => User.findOne({ where: { username: 'foo' } })) | ||
.to.throw('User.findOne() did not return a promise but should'); | ||
User.findOne({ where: { username: 'foo' } }) | ||
.should.be.rejectedWith(Error, 'User.findOne() did not return a promise but should'); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
24980
435
- Removedbluebird@^3.5.3
- Removedbluebird@3.7.2(transitive)