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.1.3 to 1.1.4

src/SequelizeSimpleCache.d.ts

2

package.json
{
"name": "sequelize-simple-cache",
"version": "1.1.3",
"version": "1.1.4",
"description": "A simple, transparent, client-side, in-memory cache for Sequelize",

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

@@ -43,2 +43,3 @@ # sequelize-simple-cache

Setup the cache along with loading your Sequelize models like this:
```javascript

@@ -48,2 +49,3 @@ const Sequelize = require('sequelize');

// create db connection
const sequelize = new Sequelize('database', 'username', 'password', { ... });

@@ -57,9 +59,11 @@

// assuming you have your models in separate files with "model definers"
// -- e.g, see below or https://github.com/sequelize/express-example --
// add your models to the cache like this
const User = cache.init(sequelize.import('./models/user'));
const Page = cache.init(sequelize.import('./models/page'));
const User = cache.init(require('./models/user')(sequelize));
const Page = cache.init(require('./models/page')(sequelize));
// 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'));
const Order = cache.init(require('./models/order')(sequelize));

@@ -71,2 +75,10 @@ // the Sequelize model API is fully transparent, no need to change anything.

`./models/user.js` might look like this:
```javascript
const { Model } = require('sequelize');
class User extends Model {}
module.exports = (sequelize) => User.init({ /* attributes */ }, { sequelize });
```
## More Details

@@ -83,2 +95,3 @@

You need to avoid non-cacheable queries, e.g., queries containing dynamic timestamps.
```javascript

@@ -102,2 +115,3 @@ const { Op, fn } = require('sequelize');

For eternal caching, i.e., no automatic cache invalidation, simply set the model's `ttl` to `false` (or any number less or equals `0`).
```javascript

@@ -114,2 +128,3 @@ const cache = new SequelizeSimpleCache({

There are these ways to clear the cache.
```javascript

@@ -131,2 +146,3 @@ const cache = new SequelizeSimpleCache({...});

You can change this default behavior like this:
```javascript

@@ -145,2 +161,3 @@ const cache = new SequelizeSimpleCache({

Caching can explicitly be bypassed like this:
```javascript

@@ -154,2 +171,3 @@ Model.noCache().findOne(...);

So, you should be able to control the size of the cache.
```javascript

@@ -167,2 +185,3 @@ const cache = new SequelizeSimpleCache({

`event` is one of: `init`, `hit`, `miss`, `load`, `purge` or `ops`.
```javascript

@@ -183,2 +202,3 @@ const cache = new SequelizeSimpleCache({

So, either clear the cache as needed in your unit tests. For example (using [mocha](https://mochajs.org/)):
```javascript

@@ -197,2 +217,3 @@ describe('My Test Suite', () => {

This is actually the way I am doing it; plus a few extra unit tests for caching.
```javascript

@@ -204,4 +225,4 @@ const config = require('config');

// loading the models
const model = sequelize.import('./models/model');
const model = require('./models/model')(sequelize);
const Model = useCache ? cache.init(model) : model;
```
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