sails-hook-redis-cache

0.1.0 • Public • Published

This hook provides an easy way to use redis as a cache service for your sails app. When enabled it will try to fetch the response for the received request from redis. If it can't be found it will continue the expected route and save the response for future requests.

Installation

npm install --save sails-hook-redis-cache

This hook is designed for sails 0.12.x only.

Usage

Create an appCache.js file in sails' config folder. The contents of that file should be as follows:

//config/appCache.js

'use strict';

module.exports.appCache = {
  
  server: {
    host: 'my-redis-server.com',
    port: 1111
  },
  
  ttl: 24 * 60 * 60, // Time to live of the cached content
  
  cachedRoutes: [
    'POST /some/route',   // The url is a path pattern as used in express. If you're using a blueprint prefix it will automatically prepend it to the path 
    'GET /some/other/route'
  ],

  enabled: true, // Enable/Disable caching. This can either be true/false or a function that returns true/false

  session: {
    enabled: false, // if `true` it will use the values of the session
                    // properties you specify below as part of the key of the cached content.
                    // This enables you to save cached content per-user 
    properties: ['user', 'role', 'authenticated']
  }
};

Readme

Keywords

none

Package Sidebar

Install

npm i sails-hook-redis-cache

Weekly Downloads

1

Version

0.1.0

License

none

Last publish

Collaborators

  • masquino