function cache(app) {
  if (app.locals.config.cacheDb && 'redis' === app.locals.config.cacheDb.connector) {
    // use redis for cache
    let redis = require("redis").createClient(app.locals.config.cacheDb);
    redis.on("error", function (err) {
      app.error(err);
    });
    // clear existing cache on startup
    redis.del('zlSites', 'themeTrees', 'themesConfig');

    return {
      // for getting data
      get: function () {
        if (3 == arguments.length) {
          // hash request
          redis.hget(arguments[0], arguments[1], arguments[2]);
        }
        else if (2 == arguments.length) {
          // key request
          redis.get(arguments[0], arguments[1]);
        }
      },
      // for setting data
      set: function () {
        if (4 == arguments.length) {
          // hash request
          redis.hset(arguments[0], arguments[1], arguments[2], arguments[3]);
        }
        else if (3 == arguments.length) {
          // key request
          redis.set(arguments[0], arguments[1], arguments[2]);
        }
      },
      // for setting volatile data with an expiration date
      setvol: function () {
        if (4 == arguments.length) {
          // key request
          redis.set(arguments[0], arguments[1], () => {
            redis.expire(arguments[0], arguments[2], arguments[3]);
          });
        }
      },
      // for deleting data
      del: function () {
        if (3 == arguments.length) {
          // hash request
          redis.hdel(arguments[0], arguments[1], arguments[2]);
        }
        else if (2 == arguments.length) {
          // key request
          redis.del(arguments[0], arguments[1]);
        }
      }
    }
  }
  else {
    // not using cache
    app.error('No config.cacheDb provided. This may affect performance.');
    let e = function() { arguments[arguments.length-1](); }
    return { get: e, set: e, setvol: e, del: e }
  }
}
function cache(app) {
  if (app.locals.config.cacheDb && 'redis' === app.locals.config.cacheDb.connector) {
    
    let redis = require("redis").createClient(app.locals.config.cacheDb);
    redis.on("error", function (err) {
      app.error(err);
    });
    
    redis.del('zlSites', 'themeTrees', 'themesConfig');

    return {
      
      get: function () {
        if (3 == arguments.length) {
          
          redis.hget(arguments[0], arguments[1], arguments[2]);
        }
        else if (2 == arguments.length) {
          
          redis.get(arguments[0], arguments[1]);
        }
      },
      
      set: function () {
        if (4 == arguments.length) {
          
          redis.hset(arguments[0], arguments[1], arguments[2], arguments[3]);
        }
        else if (3 == arguments.length) {
          
          redis.set(arguments[0], arguments[1], arguments[2]);
        }
      },
      
      setvol: function () {
        if (4 == arguments.length) {
          
          redis.set(arguments[0], arguments[1], () => {
            redis.expire(arguments[0], arguments[2], arguments[3]);
          });
        }
      },
      
      del: function () {
        if (3 == arguments.length) {
          
          redis.hdel(arguments[0], arguments[1], arguments[2]);
        }
        else if (2 == arguments.length) {
          
          redis.del(arguments[0], arguments[1]);
        }
      }
    }
  }
  else {
    
    app.error('No config.cacheDb provided. This may affect performance.');
    let e = function() { arguments[arguments.length-1](); }
    return { get: e, set: e, setvol: e, del: e }
  }
}
function cache ( app ) { if ( app . locals . config . cacheDb && 'redis' === app . locals . config . cacheDb . connector ) { // use redis for cache let redis = require ( "redis" ) . createClient ( app . locals . config . cacheDb ) ; redis . on ( "error" , function ( err ) { app . error ( err ) ; } ) ; // clear existing cache on startup redis . del ( 'zlSites' , 'themeTrees' , 'themesConfig' ) ; return { // for getting data get : function ( ) { if ( 3 == arguments . length ) { // hash request redis . hget ( arguments [ 0 ] , arguments [ 1 ] , arguments [ 2 ] ) ; } else if ( 2 == arguments . length ) { // key request redis . get ( arguments [ 0 ] , arguments [ 1 ] ) ; } } , // for setting data set : function ( ) { if ( 4 == arguments . length ) { // hash request redis . hset ( arguments [ 0 ] , arguments [ 1 ] , arguments [ 2 ] , arguments [ 3 ] ) ; } else if ( 3 == arguments . length ) { // key request redis . set ( arguments [ 0 ] , arguments [ 1 ] , arguments [ 2 ] ) ; } } , // for setting volatile data with an expiration date setvol : function ( ) { if ( 4 == arguments . length ) { // key request redis . set ( arguments [ 0 ] , arguments [ 1 ] , ( ) => { redis . expire ( arguments [ 0 ] , arguments [ 2 ] , arguments [ 3 ] ) ; } ) ; } } , // for deleting data del : function ( ) { if ( 3 == arguments . length ) { // hash request redis . hdel ( arguments [ 0 ] , arguments [ 1 ] , arguments [ 2 ] ) ; } else if ( 2 == arguments . length ) { // key request redis . del ( arguments [ 0 ] , arguments [ 1 ] ) ; } } } } else { // not using cache app . error ( 'No config.cacheDb provided. This may affect performance.' ) ; let e = function ( ) { arguments [ arguments . length - 1 ] ( ) ; } return { get : e , set : e , setvol : e , del : e } } }
currently only redis cache store is supported
currently only redis cache store is supported