Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sequelize-simple-cache

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sequelize-simple-cache - npm Package Compare versions

Comparing version 1.0.0-beta.5 to 1.0.0-beta.6

2

package.json
{
"name": "sequelize-simple-cache",
"version": "1.0.0-beta.5",
"version": "1.0.0-beta.6",
"description": "A simple, transparent, client-side, in-memory cache for Sequelize",

@@ -5,0 +5,0 @@ "main": "src/SequelizeSimpleCache.js",

@@ -17,3 +17,3 @@ # sequelize-simple-cache

This cache might work for you if you have a few database tables that
This cache might work for you if you have database tables that
(1) are frequently read but very rarely written and

@@ -26,6 +26,6 @@ (2) contain only few rows of data.

But updated only very rarely, once a day maybe.
So, pre-fetching or simple caching would work for us.
So, pre-fetching or simple in-memory caching would work for us.
If that's not matching your scenario,
better look for something more sophisticated such as Redis, memcached and alike.
better look for something more sophisticated such as Redis or Memcached.

@@ -57,7 +57,4 @@ ## Install

// no caching for this one
const Balance = sequelize.import('./models/balance');
// still no caching for this one (because it's not configured to be cached)
// will add dummy decorators to the model for a homogeneous interface to all models
// no caching for this one (because it's not configured to be cached)
// will only add dummy decorators to the model for a homogeneous interface to all models
const Order = cache.init(sequelize.import('./models/order'));

@@ -86,4 +83,4 @@

Model.findOne({ where: { startDate: { [Op.lte]: fn('NOW') }, } });
// if you don't want a query to be cached, bypass the cache like this
Model.cacheBypass().findOne({ 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(...);
```

@@ -98,7 +95,7 @@

cache.clear();
// clear all entries of one specific model
cache.clear('User');
// clear all entries of specific models
cache.clear('User', 'Page');
// or do the same on any model
Model.cacheClear();
Model.cacheClearAll();
Model.clearCache(); // only model
Model.clearCacheAll(); // entire cache
```

@@ -110,3 +107,3 @@

```javascript
Model.cacheBypass().findOne(...);
Model.noCache().findOne(...);
```

@@ -125,5 +122,5 @@

### Unit testing your models
### Unit testing
If you are unit testing your Sequelize models using [Sinon](https://sinonjs.org/) et al.,
If you are mocking your Sequelize models in unit tests with [Sinon](https://sinonjs.org/) et al.,
caching might be somewhat counterproductive.

@@ -134,3 +131,3 @@ So, either clear the cache as needed in your unit tests. For example (using [mocha](https://mochajs.org/)):

beforeEach(() => {
Model.cacheClearAll(); // on any model with the same effect
Model.clearCacheAll(); // on any model with the same effect
});

@@ -144,3 +141,3 @@ // ...

And start your unit tests with setting `NODE_ENV=test` before.
This is actually the way I am doing it; plus a few extra unit tests for explicitly testing the cache.
This is actually the way I am doing it; plus a few extra unit tests for caching.
```javascript

@@ -147,0 +144,0 @@ const config = require('config');

@@ -50,5 +50,5 @@ const Promise = require('bluebird');

/* eslint-disable no-param-reassign */
model.cacheBypass = () => model;
model.cacheClear = () => this.clear(name);
model.cacheClearAll = () => this.clear();
model.noCache = () => model;
model.clearCache = () => this.clear(name);
model.clearCacheAll = () => this.clear();
/* eslint-enable no-param-reassign */

@@ -55,0 +55,0 @@ // setup caching for this model

@@ -77,5 +77,5 @@ const chai = require('chai');

const User = cache.init(model);
expect(User).to.have.property('cacheBypass').which.is.a('function');
expect(User).to.have.property('cacheClear').which.is.a('function');
expect(User).to.have.property('cacheClearAll').which.is.a('function');
expect(User).to.have.property('noCache').which.is.a('function');
expect(User).to.have.property('clearCache').which.is.a('function');
expect(User).to.have.property('clearCacheAll').which.is.a('function');
});

@@ -145,3 +145,3 @@

const result1 = await User.findOne({ where: { username: 'fred' } });
User.cacheClear();
User.clearCache();
const result2 = await User.findOne({ where: { username: 'fred' } });

@@ -162,3 +162,3 @@ expect(stub.calledTwice).to.be.true;

const result1 = await User.findOne({ where: { username: 'fred' } });
User.cacheClearAll();
User.clearCacheAll();
const result2 = await User.findOne({ where: { username: 'fred' } });

@@ -291,3 +291,3 @@ expect(stub.calledTwice).to.be.true;

const result2 = await User.findOne({ where: { username: 'fred' } });
const result3 = await User.cacheBypass().findOne({ where: { username: 'fred' } });
const result3 = await User.noCache().findOne({ where: { username: 'fred' } });
expect(stub.calledTwice).to.be.true;

@@ -294,0 +294,0 @@ expect(result1).to.be.deep.equal({ username: 'fred' });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc