sequelize-simple-cache
Advanced tools
Comparing version 1.2.0 to 1.3.0
{ | ||
"name": "sequelize-simple-cache", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "A simple, transparent, client-side, in-memory cache for Sequelize", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -232,5 +232,2 @@ # sequelize-simple-cache | ||
Please note that -- for the sake of good typing -- the interface of `new SequelizeSimpleCache()` | ||
had to be changed slightly. | ||
A quick example: | ||
@@ -259,7 +256,6 @@ | ||
// create cache -- referring to Sequelize models by name, e.g., `User` | ||
const cache = new SequelizeSimpleCache([{ | ||
name: 'User', ttl: 5 * 60, // 5 minutes | ||
}, { | ||
name: 'Page', // default ttl is 1 hour | ||
}]); | ||
const cache = new SequelizeSimpleCache({ | ||
[User.name]: { ttl: 5 * 60 }, // 5 minutes | ||
'Foo': {}, // default ttl is 1 hour | ||
}); | ||
@@ -266,0 +262,0 @@ // add User model to the cache |
import { Model, ModelCtor, ModelStatic } from "sequelize"; | ||
export default class SequelizeSimpleCache { | ||
constructor(config: SequelizeSimpleCacheConfig[], options?: SequelizeSimpleCacheOptions); | ||
constructor(config: SequelizeSimpleCacheConfig, options?: SequelizeSimpleCacheOptions); | ||
init<M extends Model>(model: ModelStatic<M>) : ModelCtor<M> & SequelizeSimpleCacheModel<M>; | ||
@@ -10,3 +10,6 @@ clear(modelnames?: string[]): void; | ||
export interface SequelizeSimpleCacheConfig { | ||
name: string; | ||
[modelname: string]: SequelizeSimpleCacheModelConfig; | ||
} | ||
export interface SequelizeSimpleCacheModelConfig { | ||
ttl?: number; | ||
@@ -13,0 +16,0 @@ limit?: number; |
@@ -20,6 +20,3 @@ const md5 = require('md5'); | ||
}; | ||
const configHash = Array.isArray(config) // alternative interface for TypeScript | ||
? config.reduce((acc, { name, ...rest }) => ({ ...acc, [name]: rest }), {}) | ||
: config; | ||
this.config = Object.entries(configHash) | ||
this.config = Object.entries(config) | ||
.reduce((acc, [type, { | ||
@@ -26,0 +23,0 @@ ttl = defaults.ttl, |
@@ -45,3 +45,7 @@ import 'mocha'; | ||
const cache = new SequelizeSimpleCache([{ name: User.name, ttl: 60000 }], { | ||
const cache = new SequelizeSimpleCache({ | ||
[User.name]: { ttl: 60000 }, | ||
foo: {}, | ||
bar: { ttl: 10000 }, | ||
}, { | ||
debug: true, delegate: (event, details) => { debugSpy.push(event) } | ||
@@ -48,0 +52,0 @@ }); |
@@ -32,6 +32,2 @@ const sinon = require('sinon'); | ||
it('should create cache without crashing / empty args / 1 / config array', () => { | ||
expect(() => new SequelizeSimpleCache([], {})).to.not.throw(); | ||
}); | ||
it('should create cache without crashing / empty args / 2', () => { | ||
@@ -45,6 +41,2 @@ expect(() => new SequelizeSimpleCache({}, { ops: false })).to.not.throw(); | ||
it('should create cache without crashing / dummy model / config array', () => { | ||
expect(() => new SequelizeSimpleCache([{ name: 'User' }], { ops: false })).to.not.throw(); | ||
}); | ||
it('should generate unique hashes for Sequelize queries with ES6 symbols and functions', () => { | ||
@@ -80,3 +72,3 @@ const queries = [{ | ||
it('should create decorations on model / cached / config array', async () => { | ||
it('should create decorations on model / cached', async () => { | ||
const stub = sinon.stub().resolves({ username: 'fred' }); | ||
@@ -87,3 +79,3 @@ const model = { | ||
}; | ||
const cache = new SequelizeSimpleCache([{ name: 'User' }], { ops: false }); | ||
const cache = new SequelizeSimpleCache({ User: {} }, { ops: false }); | ||
const User = cache.init(model); | ||
@@ -215,3 +207,3 @@ expect(User.noCache).to.be.a('function'); | ||
it('should cache but expire after ttl / config array', async () => { | ||
it('should cache but expire after ttl', async () => { | ||
const stub = sinon.stub().resolves({ username: 'fred' }); | ||
@@ -222,3 +214,3 @@ const model = { | ||
}; | ||
const cache = new SequelizeSimpleCache([{ name: 'User', ttl: 1 }], { ops: false }); | ||
const cache = new SequelizeSimpleCache({ User: { ttl: 1 } }, { ops: false }); | ||
const User = cache.init(model); | ||
@@ -235,3 +227,3 @@ const result1 = await User.findOne({ where: { username: 'fred' } }); | ||
it('should cache forever / config array', async () => { | ||
it('should cache forever', async () => { | ||
const stub = sinon.stub().resolves({ username: 'fred' }); | ||
@@ -242,3 +234,3 @@ const model = { | ||
}; | ||
const cache = new SequelizeSimpleCache([{ name: 'User', ttl: false }], { ops: false }); | ||
const cache = new SequelizeSimpleCache({ User: { ttl: false } }, { ops: false }); | ||
const User = cache.init(model); | ||
@@ -245,0 +237,0 @@ const result1 = await User.findOne({ where: { username: 'fred' } }); |
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
51880
1024
267