npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

redis-cache-sequelize

v1.7.3

Published

Helps in caching sequelize objects

Readme

Redis Cache for Sequelize

Build Status Dependency Status Code Climate

This helps in caching sequelize objects in redis based on 3 strategies and not queries. There are methods like #search , #setCache and #expire for handling your caches based on id, action for setting caches and searching based on id, action, all and expiry based on id, action and all. These caches are in context of some object and are not global. For example:

  • A cache for the api response /users/connections for User with id 1 will be different than that of the User with id 2.
Initialization and configuration
  • It is basically namespaced globally and you can do that by providing options.namespace while initializing the cacheStore :

  var initCacheStore = require("redis-cache-sequelize");
  var cacheStore = initCacheStore(redisClient, {namespace: 'VADER'});
  • We are using sequelize models for using this as of now.

    var redisClient = redis.createClient(redisPort, redisHost);
    db = new Sequelize(opts.database, opts.username, opts.password, opts);
    cacheStore = initCacheStore(redisClient, {namespace: 'VADER'});

    User = db.define('User', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER
      },
      name: {
        type: Sequelize.STRING(255)
      }
    }, {
      instanceMethods: {
        toApi: function() {
          return {
            name: this.name
          }
        }
      }
    });

    User.sync({force: true})
      .then(function() {
        return done();
      })
      .catch(onErr);
    /**
    * enabled - decides if this cacheStore will enable caching or not. 
    * ttl - Time to live for the redis objects. After that the entire cacheStore expires.
    */
    var userCache = cacheStore(User, {ttl: 500, enabled: true});

Setting Cache:

#setCache returns a promise that resolves by successfully setting the cache and returns the result.

#setCache with id only - {id: <id>}

You can set cache which always needs an id and / or with action. Pattern is restricted while setting cache for obvious reasons.

Global Namespace : javascript VADER Model: javascript User id: javascript 1

The key will be formed as javascript VADER::User::1

  • Usage
  userCache.setCache(_data, {id: 1})
    .then(_data => // Use the data)
    .catch(_err => // Handle Error)

setCache with id and action

Global Namespace: javascript VADER Model: javascript User id: javascript 1 Action: javascript "connections"

The key will be formed as javascript VADER::USER::CONNECTIONS::1

  • Usage
  userCache.setCache(_data, {action: 'connections', id: 1})
    .then(_data => // Use the data)
    .catch(_err => // Handle Error)

Searching in Cache

#search provides multiple ways to search the cached objects:

  • {id: <id>}
  • {id: <id>, action: <action>}
  • {id: <id>, all: true}
#search with just id - { id: <id> } :

This basically searches based on the id of the object, a global namespace is present which is set while initializing the cache and apart from that the model name is used as the secondary namespace. For example :

Global Namespace : javascript VADER Model: javascript User id: javascript 1

The key will be formed as javascript VADER::User::1

  • Usage
  userCache.search({id: 1})
    .then(_data => // Use the data)
    .catch(_err => // Handle Error)
#search with id and action - { id: <id>, action: <action> } :

This basically searches based on actions or however you set the keys.

Global Namespace: javascript VADER Model: javascript User Action: javascript ALL id: javascript 1

The key will be formed as javascript VADER::USER::ALL::1

  • Usage
  userCache.search({action: 'ALL', id: 1})
    .then(_data => // Use the data)
    .catch(_err => // Handle Error)
#search for all cached objects for that id - { id: <id>, all: <boolean> } :

This searches for all the cached objects for the mentioned id with a key pattern.

Global Namespace: javascript VADER Model: javascript User id: javascript 1

The key will be formed as javascript VADER::User*1

  • Usage
  userCache.search({id: 1, all: true })
    .then(_data => // Use the data)
    .catch(_err => // Handle Error)

Expiring Cache :

#expire provides multiple ways to search the cached objects:

  • {id: <id>}
  • {id: <id>, action: <action>}
  • {id: <id>, all: true}
  • {expire_all: true}
#expire with just id - { id: <id> } :

This expires a particular cache object for that id.

Global Namespace : javascript VADER Model: javascript User id: javascript 1

The key will be formed as javascript VADER::User::1

  • Usage
  userCache.expire({id: 1})
    .then(_data => // Use the data)
    .catch(_err => // Handle Error)
#expire with id and action - { id: <id>, action: <action> } :

This basically expires based on actions or however you set the keys.

Global Namespace: javascript VADER Model: javascript User Action: javascript ALL id: javascript 1

The key will be formed as javascript VADER::USER::ALL::1

  • Usage
  userCache.expire({action: 'ALL', id: 1})
    .then(_data => // Use the data)
    .catch(_err => // Handle Error)
#expire for all cached objects for that id - { id: <id>, all: <boolean> } :

This expires all the cached objects for the mentioned id with a key pattern.

Global Namespace: javascript VADER Model: javascript User id: javascript 1

The key will be formed as javascript VADER::User*1

  • Usage
  userCache.expire({id: 1, all: true })
    .then(_data => // Use the data)
    .catch(_err => // Handle Error)
#expire for all cached objects available - { expire_all: <boolean> } :

This expires all the cached objects for the model with a key pattern.

Global Namespace: javascript VADER Model: javascript User

The key will be formed as javascript VADER::User*

  • Usage
  userCache.expire({expire_all: true })
    .then(_data => // Use the data)
    .catch(_err => // Handle Error)

Searching with legacy functions:

  • These are deprecated, will be removed in future releases. Please use #search instead.
searchOne

This basically searches based on the id of the object, a global namespace is present which is set while initializing the cache and apart from that the model name is used as the secondary namespace. For example :

Global Namespace : javascript VADER Model: javascript User id: javascript 1

The key will be formed as javascript VADER::User::1

  • Usage
userCache.searchOne({id: 1})
    .then(function(result) {  
      /** */
    })
searchScoped

This basically searches based on actions / methods or however you set the keys. It's agostic of that at the moment intentionally.

Global Namespace: javascript VADER Model: javascript User Scope/Method/Action: javascript ALL id: javascript 1

The key will be formed as javascript VADER::USER::ALL::1

  • Usage
userCache.searchScoped({action: 'ALL', id: 1})
    .then(function(result) {  
      /** */
    })
searchPattern

This searches all keys based on the pattern provided

Global Namespace: javascript VADER Model: javascript User id: javascript 1 Pattern: javascript "*"

The key will be formed as javascript VADER::USER::1::*

  • Usage
userCache.searchPattern({action: '*', id: 1})
    .then(function(result) {  
      /** */
    })

Cache Expiry

expireOne

This expires a particular value based on the key generated from what you pass in options.

Global Namespace : javascript VADER Model: javascript User id: javascript 1

The key will be formed as javascript VADER::User::1

  • Usage
userCache.expireOne({id: 1})
    .then(function(result) {  
      /** */
    })