diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..ff3059c --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["@babel/preset-env"] +} \ No newline at end of file diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..7234583 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,25 @@ +{ + "env": { + "es6": true, + "node": true, + "mocha": true + }, + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module" + }, + "extends": [ + "prettier", + "prettier/standard" + ], + "plugins": [ + "prettier" + ], + "rules": { + "prettier/prettier": "error", + "no-var": 1, + "prefer-arrow-callback": 1, + "prefer-template": 1, + "no-console": 0 + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 765fdaf..22ba979 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ -/node_modules/* -package-lock.json \ No newline at end of file +node_modules +package-lock.json +dist +dump.rdb diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..07f6b38 --- /dev/null +++ b/.npmignore @@ -0,0 +1,2 @@ +lib +docs \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 1710f60..3f5e00c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,16 @@ CHANGE LOG ========== +# Changes between 1.x.x and 2.0.0 + +## Disclaimer + +This major version has been reworked to avoid breaking changes but some edge-cases may exist. + +## New Features + +???? + # Changes between 0.0.8 and 0.1.x ## Disclaimer diff --git a/bin/express-redis-cache.js b/bin/express-redis-cache.js index ba83a57..e7ba747 100755 --- a/bin/express-redis-cache.js +++ b/bin/express-redis-cache.js @@ -1,270 +1,271 @@ #!/usr/bin/env node -module.exports = (function () { - - 'use strict'; - - require('colors'); - - var pkg = require('../package.json'); - - var domain = require('domain').create(); - - domain.on('error', function (error) { - throw error; +module.exports = (function() { + "use strict"; + + require("colors"); + + let pkg = require("../package.json"); + + /** Get configuration from command line if any **/ + + let port, + host, + prefix, + skip = []; + + process.argv = process.argv.map((argv, i, all) => { + if (argv === "--prefix" && process.argv[i + 1]) { + prefix = process.argv[i + 1]; + skip.push(i + 1); + } else if (argv === "--port" && process.argv[i + 1]) { + port = process.argv[i + 1]; + skip.push(i + 1); + } else if (argv === "--host" && process.argv[i + 1]) { + host = process.argv[i + 1]; + skip.push(i + 1); + } else if (skip.indexOf(i) === -1) { + return argv; + } }); - domain.run(function () { - - /** Get configuration from command line if any **/ + skip = undefined; - var port, host, prefix, skip = []; + /** Iniatilize express-redis-cache **/ - process.argv = process.argv.map(function (argv, i, all) { - if ( argv === '--prefix' && process.argv[(i + 1)] ) { - prefix = process.argv[(i + 1)]; - skip.push(i + 1); - } - - else if ( argv === '--port' && process.argv[(i + 1)] ) { - port = process.argv[(i + 1)]; - skip.push(i + 1); - } + let cache; - else if ( argv === '--host' && process.argv[(i + 1)] ) { - host = process.argv[(i + 1)]; - skip.push(i + 1); - } - - else if ( skip.indexOf(i) === -1 ) { - return argv; - } + function connect() { + cache = require("../")({ + host: host, + port: port, + prefix: prefix || pkg.config.prefix }); - skip = undefined; - - /** Iniatilize express-redis-cache **/ - - var cache; - - function connect () { - cache = require('../')({ - host: host, - port: port, - prefix: prefix || pkg.config.prefix - }); - - cache - - .on('error', function (error) { - error.stack.split(/\n/).forEach(function (line) { - console.log(line.yellow); - }); - }) + cache - .on('message', function (message) { - console.log(message.grey); + .on("error", error => { + error.stack.split(/\n/).forEach(line => { + console.log(line.yellow); }); - } - - /** A function to pretty print a cache entry **/ - - function formatEntry (entry) { - try { - var moment = require('moment'); - - var iso = new Date(+entry.touched).toISOString(); - - /** Name **/ - console.log(' ' + entry.name.blue.bold); - - /** Touched **/ - console.log(' %s %s', 'touched'.yellow, - moment(iso, moment.ISO_8601).fromNow()); - - /** Expire **/ - console.log(' %s %s', 'expires'.yellow, - (function () { - if ( entry.expire < 0 || typeof expire === 'undefined' ) { - return 'NEVER'; - } - else { - var expire = ( +entry.touched + ((+entry.expire || 0) * 1000)); - - var iso2 = new Date(expire).toISOString(); - - return moment(iso2, moment.ISO_8601).fromNow(); - } - })()); - - /** Object size in bytes **/ - console.log(' %s %s bytes ' + '%s KB'.grey, - 'size'.yellow, - require('../lib/sizeof')(entry), - (require('../lib/sizeof')(entry) / 1024).toFixed(2)); - - /** Body length **/ - console.log(' %s %s', 'body'.yellow, entry.body.length + - ' characters'); - } - catch ( error ) { - return console.log(' Not readable'.red, entry, error); - } - } - - /** Switch action **/ - - switch ( process.argv[2] ) { - - /** - HELP - **/ - - case undefined: - case '-h': - case '--help': - case 'help': + }) - console.log(' express-redis-cache v%s'.yellow, pkg.version); - console.log(); - console.log(' Cache the response of a HTTP request inside a Redis list and let you manage your cache entries'.cyan); - console.log(); - console.log(' Commands:'); - console.log(); - - console.log(' add --type='.bold.yellow); - console.log(' Add a new cache entry'); - console.log(' # Cache simple text'); - console.log(' express-redis-cache add "test" "This is a test";'.cyan); - console.log(' # Cache a file'); - console.log(' express-redis-cache add "home" "$(cat index.html)";'.cyan); - console.log(' # Cache a JSON object'); - console.log(" express-redis-cache add \"user1:location\" '{ \"lat\": 4.7453, \"lng\": -31.332 }' --type json;".cyan); - console.log(' # Cache a text that will expire in one hour'); - console.log(' express-redis-cache add "offer" "everything 25% off for the next hour" $(( 60 * 60 ));'.cyan); - console.log(); - - console.log(' get '.bold.yellow); - console.log(' Get a single cache entry by name'); - console.log(' # Get all cache entries for default prefix'); - console.log(' express-redis-cache get'.cyan); - console.log(); - - console.log(' del '.bold.yellow); - console.log(' Delete a cache entry'); - console.log(' express-redis-cache del favorite-movie'.cyan); - console.log(); - - console.log(' size'.bold.yellow); - console.log(' Get cache size for all entries'); - console.log(); - - console.log(' NOTE'.bold.yellow); - - console.log(' express-redis-cache connects to Redis using localhost as default and Redis default port. You can override that using the options: --port --host . Ditto for --prefix .'.cyan); + .on("message", message => { + console.log(message.grey); + }); + } - console.log(); + /** A function to pretty print a cache entry **/ - break; + function formatEntry(entry) { + try { + let moment = require("moment"); - /** - LS - **/ + let iso = new Date(+entry.touched).toISOString(); - case 'ls': + /** Name **/ + console.log(` ${entry.name.blue.bold}`); - connect(); + /** Touched **/ + console.log( + " %s %s", + "touched".yellow, + moment(iso, moment.ISO_8601).fromNow() + ); - cache.ls(domain.intercept(function (entries) { + /** Expire **/ + console.log( + " %s %s", + "expires".yellow, + (function() { + if (entry.expire < 0 || typeof expire === "undefined") { + return "NEVER"; + } else { + var expire = +entry.touched + (+entry.expire || 0) * 1000; - cache.client.quit(); + let iso2 = new Date(expire).toISOString(); - if ( ! entries.length ) { - console.log(' [empty]'.grey); - } - else { - entries.forEach(formatEntry); + return moment(iso2, moment.ISO_8601).fromNow(); } + })() + ); + + /** Object size in bytes **/ + console.log( + ` %s %s bytes ${"%s KB".grey}`, + "size".yellow, + require("../lib/sizeof")(entry), + (require("../lib/sizeof")(entry) / 1024).toFixed(2) + ); + + /** Body length **/ + console.log( + " %s %s", + "body".yellow, + `${entry.body.length} characters` + ); + } catch (error) { + return console.log(" Not readable".red, entry, error); + } + } + + /** Switch action **/ + + switch (process.argv[2]) { + /** + HELP + **/ + + case undefined: + case "-h": + case "--help": + case "help": + console.log(" express-redis-cache v%s".yellow, pkg.version); + console.log(); + console.log( + " Cache the response of a HTTP request inside a Redis list and let you manage your cache entries" + .cyan + ); + console.log(); + console.log(" Commands:"); + console.log(); + + console.log(" add --type=".bold.yellow); + console.log(" Add a new cache entry"); + console.log(" # Cache simple text"); + console.log(' express-redis-cache add "test" "This is a test";'.cyan); + console.log(" # Cache a file"); + console.log( + ' express-redis-cache add "home" "$(cat index.html)";'.cyan + ); + console.log(" # Cache a JSON object"); + console.log( + ' express-redis-cache add "user1:location" \'{ "lat": 4.7453, "lng": -31.332 }\' --type json;' + .cyan + ); + console.log(" # Cache a text that will expire in one hour"); + console.log( + ' express-redis-cache add "offer" "everything 25% off for the next hour" $(( 60 * 60 ));' + .cyan + ); + console.log(); + + console.log(" get ".bold.yellow); + console.log(" Get a single cache entry by name"); + console.log(" # Get all cache entries for default prefix"); + console.log(" express-redis-cache get".cyan); + console.log(); + + console.log(" del ".bold.yellow); + console.log(" Delete a cache entry"); + console.log(" express-redis-cache del favorite-movie".cyan); + console.log(); + + console.log(" size".bold.yellow); + console.log(" Get cache size for all entries"); + console.log(); + + console.log(" NOTE".bold.yellow); + + console.log( + " express-redis-cache connects to Redis using localhost as default and Redis default port. You can override that using the options: --port --host . Ditto for --prefix ." + .cyan + ); + + console.log(); + + break; + + /** + LS + **/ + + case "ls": + connect(); + + cache.get((err, entries) => { + cache.client.quit(); + + if (!entries.length) { + console.log(" [empty]".grey); + } else { + entries.forEach(formatEntry); + } + }); + break; - })); - break; - - /** - SIZE - **/ - - case 'size': - - connect(); - - cache.size(domain.intercept(function (size) { - - cache.client.quit(); + /** + SIZE + **/ - console.log('Size: %d bytes, %d KB, %d MB', - size, - (size / 1024).toFixed(2), - (size / (1024 * 1024)).toFixed(2)); + case "size": + connect(); - })); - break; + cache.size(size => { + cache.client.quit(); - /** - ADD - **/ + console.log( + "Size: %d bytes, %d KB, %d MB", + size, + (size / 1024).toFixed(2), + (size / (1024 * 1024)).toFixed(2) + ); + }); + break; - case 'add': - if ( ! process.argv[3] || ! process.argv[4] ) { - throw new Error('Missing arguments'); - } + /** + ADD + **/ - connect(); + case "add": + if (!process.argv[3] || !process.argv[4]) { + throw new Error("Missing arguments"); + } - cache.add(process.argv[3], process.argv[4], { expire: +process.argv[5] }, domain.intercept(function (name, entry) { + connect(); + cache.add( + process.argv[3], + process.argv[4], + { expire: +process.argv[5] }, + (name, entry) => { cache.client.quit(); entry.name = name; formatEntry(entry); - })); - break; - - /** - DEL - **/ - - case 'del': - - connect(); - - cache.del(process.argv[3], domain.intercept(function (occ) { - - cache.client.quit(); + } + ); + break; - console.log(' %d deletions', occ); - })); - break; + /** + DEL + **/ - /** - GET - **/ + case "del": + connect(); - case 'get': + cache.del(process.argv[3], occ => { + cache.client.quit(); - connect(); + console.log(" %d deletions", occ); + }); + break; - cache.get(process.argv[3], domain.intercept(function (entries) { + /** + GET + **/ - cache.client.quit(); + case "get": + connect(); - entries.forEach(function (entry) { - formatEntry(entry); - }); - - })); - break; - } - }); + cache.get(process.argv[3], entries => { + cache.client.quit(); + entries.forEach(entry => { + formatEntry(entry); + }); + }); + break; + } })(); diff --git a/docs/express-redis-cache/2.0.0/ExpressRedisCache.html b/docs/express-redis-cache/2.0.0/ExpressRedisCache.html new file mode 100644 index 0000000..6b00df6 --- /dev/null +++ b/docs/express-redis-cache/2.0.0/ExpressRedisCache.html @@ -0,0 +1,1999 @@ + + + + + + ExpressRedisCache - Documentation + + + + + + + + + + + + + + + + + +
+ +

ExpressRedisCache

+ + + + + + + +
+ +
+ +

+ ExpressRedisCache +

+ +

ExpressRedisCache

+ + +
+ +
+
+ + +
+ + +

Constructor

+ + +

new ExpressRedisCache(options?)

+ + + + + +
+

Main class

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
options? + + +Object + + + + +

Options (view README)

+ +
+ + + + + + + + + + + + + + + + +
+ +
+ + +

Extends

+ + + + +
    +
  • EventEmitter
  • +
+ + + + + + + + + + + + + +

Members

+ + + +
+

auth_pass :String

+ + + + +
+

The password of Redis server (optional)

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +String + + +
  • +
+ + + + + +
+ + + +
+

client :Object

+ + + + +
+

The Redis Client

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
+ + + +
+

connected :Boolean

+ + + + +
+

Whether or not express-redis-cache is connected to Redis

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Boolean + + +
  • +
+ + + + + +
+ + + +
+

expire :number

+ + + + +
+

Set expiration time in seconds, default is -1 (No expire)

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + +
+

FOREVER :number

+ + + + +
+

An alias to disable expiration for a specific route

+

var cache = new ExpressRedisCache(); + cache.route('page', cache.FOREVER); // cache will not expire

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + +
+

host :String

+ + + + +
+

The host to connect to (default host if null)

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +String + + +
  • +
+ + + + + +
+ + + +
+

options :Object

+ + + + +
+

The request options

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
+ + + +
+

port :Number

+ + + + +
+

The port to connect to (default port if null)

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + +
+ + + +
+

prefix :String

+ + + + +
+

The entry name prefix

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + +
Type:
+
    +
  • + +String + + +
  • +
+ + + + + +
+ + + + + +

Methods

+ + + +
+ + + +

(static) del(name, callback)

+ + + + + +
+

Delete entry by name

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + + +

The entry name

+ +
callback + + +function + + + + + + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + + +
+

null

+
+ + +
+ + + +
+ + +
+ + + +

(static) route() → {function}

+ + + + + +
+

route() - Create a middleware

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +function + + +
+
+ + +
+

middleware

+
+ + +
+ + + +
+ + +
+ + + +

add(arg) → {Object}

+ + + + + +
+

This is a method

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
arg + + +Object + + + + +

About arg

+ +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Object + + +
+
+ + +
+

void

+
+ + +
+ + + +
+ + +
+ + + +

del(arg) → {Object}

+ + + + + +
+

This is a method

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
arg + + +Object + + + + +

About arg

+ +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Object + + +
+
+ + +
+

void

+
+ + +
+ + + +
+ + +
+ + + +

get(arg) → {Object}

+ + + + + +
+

Get -

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
arg + + +Object + + + + +

About arg

+ +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Object + + +
+
+ + +
+

void

+
+ + +
+ + + +
+ + +
+ + + +

route(arg) → {Object}

+ + + + + +
+

This is a method

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
arg + + +Object + + + + +

About arg

+ +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Object + + +
+
+ + +
+

void

+
+ + +
+ + + +
+ + +
+ + + +

size(arg) → {Object}

+ + + + + +
+

This is a method

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
arg + + +Object + + + + +

About arg

+ +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Object + + +
+
+ + +
+

void

+
+ + +
+ + + +
+ + + + + + +
+ +
+ + + + +
+ +
+ +
+ Generated by JSDoc 3.5.5 on Fri Aug 10 2018 14:37:11 GMT+0200 (CEST) using the Minami theme. +
+ + + + + \ No newline at end of file diff --git a/docs/express-redis-cache/2.0.0/ExpressRedisCache_add.js.html b/docs/express-redis-cache/2.0.0/ExpressRedisCache_add.js.html new file mode 100644 index 0000000..299fe8d --- /dev/null +++ b/docs/express-redis-cache/2.0.0/ExpressRedisCache_add.js.html @@ -0,0 +1,134 @@ + + + + + + ExpressRedisCache/add.js - Documentation + + + + + + + + + + + + + + + + + +
+ +

ExpressRedisCache/add.js

+ + + + + + + +
+
+
import util from "util";
+import { config } from "../../package.json";
+import sizeOf from "../sizeof";
+
+/**  Add
+ *
+ *  @function
+ *  @description Add a new cache entry
+ *  @return void
+ *  @callback
+ *  @arg {String} name - The cache entry name
+ *  @arg {String} body - The cache entry body
+ *  @arg {Object} options - Optional { type: String, expire: Number }
+ *  @arg {Number} expire - The cache life time in seconds [OPTIONAL]
+ *  @arg {Function} callback
+ */
+
+function add(name, body, options, callback) {
+  var self = this;
+
+  /** Adjust arguments in case @options is omitted **/
+  if (!callback && typeof options === "function") {
+    callback = options;
+    options = {};
+  }
+
+  if (self.connected === false) {
+    return callback(null, []); // simulate cache miss
+  }
+
+  /** The new cache entry **/
+  var entry = {
+    body: body,
+    type: options.type || config.type,
+    touched: +new Date(),
+    expire:
+      typeof options.expire !== "undefined" && options.expire !== false
+        ? options.expire
+        : self.expire
+  };
+
+  var size = sizeOf(entry);
+
+  var prefix = self.prefix.match(/:$/)
+    ? self.prefix.replace(/:$/, "")
+    : self.prefix;
+
+  /* Save as a Redis hash */
+  var redisKey = prefix + ":" + name;
+  self.client.hmset(redisKey, entry, function(err, res) {
+    var calculated_size = (size / 1024).toFixed(2);
+    /** If @expire then tell Redis to expire **/
+    if (typeof entry.expire === "number" && entry.expire > 0) {
+      self.client.expire(redisKey, +entry.expire, function() {
+        const message = util.format(
+          "SET %s ~%d Kb %d TTL (sec)",
+          redisKey,
+          calculated_size,
+          +entry.expire
+        );
+        self.emit("message", message);
+        callback(null, name, entry, res);
+      });
+    } else {
+      self.emit(
+        "message",
+        util.format("SET %s ~%d Kb", redisKey, calculated_size)
+      );
+      callback(null, name, entry, res);
+    }
+  });
+}
+
+export default add;
+
+
+
+ + + + +
+ +
+ +
+ Generated by JSDoc 3.5.5 on Fri Aug 10 2018 14:37:11 GMT+0200 (CEST) using the Minami theme. +
+ + + + + diff --git a/docs/express-redis-cache/2.0.0/ExpressRedisCache_del.js.html b/docs/express-redis-cache/2.0.0/ExpressRedisCache_del.js.html new file mode 100644 index 0000000..6027f3d --- /dev/null +++ b/docs/express-redis-cache/2.0.0/ExpressRedisCache_del.js.html @@ -0,0 +1,139 @@ + + + + + + ExpressRedisCache/del.js - Documentation + + + + + + + + + + + + + + + + + +
+ +

ExpressRedisCache/del.js

+ + + + + + + +
+
+
import util from "util";
+import async from "async";
+
+/**  Delete cache entries
+ *
+ *  @method ExpressRedisCache.del
+ *  @description Delete entry by name
+ *  @return null
+ *  @arg {String} name - The entry name
+ *  @arg {Function} callback
+ */
+
+function del(name, callback) {
+  var self = this;
+
+  if (typeof name !== "string") {
+    return this.emit(
+      "error",
+      new Error("ExpressRedisCache.del: missing first argument String")
+    );
+  }
+
+  if (typeof callback !== "function") {
+    return this.emit(
+      "error",
+      new Error("ExpressRedisCache.del: missing second argument Function")
+    );
+  }
+
+  /** Get prefix */
+
+  var prefix = self.prefix.match(/:$/)
+    ? self.prefix.replace(/:$/, "")
+    : self.prefix;
+
+  /** Tell Redis to delete hash */
+
+  var redisKey = prefix + ":" + name;
+
+  /** Detect wilcard syntax */
+
+  var hasWildcard = redisKey.indexOf("*") >= 0;
+
+  /** If has wildcard */
+
+  if (hasWildcard) {
+    /** Get a list of keys using the wildcard */
+
+    self.client.keys(redisKey, function onKeys(err, keys) {
+      async.each(
+        keys,
+
+        function onEachKey(key, callback) {
+          self.client.del(key, function() {
+            self.emit("message", util.format("DEL %s", key));
+            callback();
+          });
+        },
+
+        function onEachKeyDone(error) {
+          if (error) {
+            throw error;
+          }
+
+          callback(null, keys.length);
+        }
+      );
+    });
+  } else {
+    /** No wildcard **/
+
+    self.client.del(redisKey, function onKeyDeleted(err, deletions) {
+      self.emit("message", util.format("DEL %s", redisKey));
+      callback(null, +deletions);
+    });
+  }
+}
+
+export default del;
+
+
+
+ + + + +
+ +
+ +
+ Generated by JSDoc 3.5.5 on Fri Aug 10 2018 14:37:11 GMT+0200 (CEST) using the Minami theme. +
+ + + + + diff --git a/docs/express-redis-cache/2.0.0/ExpressRedisCache_get.js.html b/docs/express-redis-cache/2.0.0/ExpressRedisCache_get.js.html new file mode 100644 index 0000000..40f7ab3 --- /dev/null +++ b/docs/express-redis-cache/2.0.0/ExpressRedisCache_get.js.html @@ -0,0 +1,141 @@ + + + + + + ExpressRedisCache/get.js - Documentation + + + + + + + + + + + + + + + + + +
+ +

ExpressRedisCache/get.js

+ + + + + + + +
+
+
import async from "async";
+import util from "util";
+import sizeOf from "../sizeof";
+
+/**  Get
+ *
+ *  @function
+ *  @return void
+ *  @callback
+ *  @arg {String} name - The cache entry name to get (wildcards accepted)
+ *  @arg {Function} callback - Callback
+ */
+
+function get(name, callback) {
+  var self = this;
+
+  if (typeof name === "function") {
+    callback = name;
+    name = "*";
+  }
+
+  var prefix = self.prefix.match(/:$/)
+    ? self.prefix.replace(/:$/, "")
+    : self.prefix;
+
+  var redisKey = prefix + ":" + (name || "*");
+
+  /** Detect wildcard syntax */
+  var hasWildcard = redisKey.indexOf("*") >= 0;
+
+  var fetchKey = function(key, cb) {
+    self.client.hgetall(key, function(err, result) {
+      if (result) {
+        var names = key.split(":");
+        result.name = names[1];
+        result.prefix = names[0];
+        self.emit(
+          "message",
+          util.format("GET %s ~%d Kb", key, (sizeOf(result) / 1024).toFixed(2))
+        );
+      }
+      cb(err, result);
+    });
+  };
+
+  /** If has wildcard */
+
+  if (hasWildcard) {
+    /** Get a list of keys using the wildcard */
+
+    self.client.keys(prefix + ":" + name, function(err, keys) {
+      if (!keys.length) {
+        callback(null, []);
+        return;
+      }
+
+      async.parallel(
+        keys.map(function(key) {
+          return function(cb) {
+            return fetchKey(key, cb);
+          };
+        }),
+        function(err, results) {
+          callback(null, results);
+        }
+      );
+    });
+  } else {
+    /** No wildcard **/
+
+    fetchKey(redisKey, function(err, result) {
+      if (result) {
+        callback(err, [result]);
+      } else {
+        callback(err, []);
+      }
+    });
+  }
+}
+
+export default get;
+
+
+
+ + + + +
+ +
+ +
+ Generated by JSDoc 3.5.5 on Fri Aug 10 2018 14:37:11 GMT+0200 (CEST) using the Minami theme. +
+ + + + + diff --git a/docs/express-redis-cache/2.0.0/ExpressRedisCache_route.js.html b/docs/express-redis-cache/2.0.0/ExpressRedisCache_route.js.html new file mode 100644 index 0000000..90a8b09 --- /dev/null +++ b/docs/express-redis-cache/2.0.0/ExpressRedisCache_route.js.html @@ -0,0 +1,253 @@ + + + + + + ExpressRedisCache/route.js - Documentation + + + + + + + + + + + + + + + + + +
+ +

ExpressRedisCache/route.js

+ + + + + + + +
+
+
import Expire from "./expire";
+
+/** route() - Create a middleware
+ *
+ *  @method ExpressRedisCache.route
+ *  @return {Function} middleware
+ */
+
+function route() {
+  /** A reference to this
+   *
+   *  @type ExpressRedisCache
+   */
+
+  var self = this;
+
+  /** The route options
+   *
+   *  @type List
+   */
+
+  var options = arguments;
+
+  // Build the middleware function
+
+  /**
+   *  @function
+   *  @arg {IncomingMessage} req
+   *  @arg {HttpResponse} res
+   *  @arg {Function} next
+   */
+
+  return function expressRedisCache_Middleware(req, res, next) {
+    if (res.expressRedisCache) {
+      self.emit("deprecated", {
+        deprecated: "expressRedisCache",
+        substitute: "use_express_redis_cache",
+        file: __filename, // eslint-disable-line
+        line: __line // eslint-disable-line
+      });
+
+      res.use_express_redis_cache = res.expressRedisCache;
+    }
+
+    // If cache is disabled, call next()
+    if (res.use_express_redis_cache === false) {
+      return next();
+    }
+
+    // If the cache isn't connected, call next()
+
+    if (self.connected === false || self.client.connected === false) {
+      return next();
+    }
+
+    /** Cache entry name
+     *
+     *  @type String
+     *  @description The name the cache entry will be saved under
+     *  @default req.originalUrl
+     */
+
+    var name = req.originalUrl;
+
+    /**
+     *  @deprecated `res.expressRedisCacheName` is deprecated starting on v0.1.1, `use res.express_redis_cache_name` instead
+     */
+
+    if (res.expressRedisCacheName) {
+      self.emit("deprecated", {
+        deprecated: "expressRedisCacheName",
+        substitute: "express_redis_cache_name",
+        file: __filename,
+        line: __line // eslint-disable-line
+      });
+
+      res.express_redis_cache_name = res.expressRedisCacheName;
+    }
+
+    // If a cache has been explicitly attached to `res` then use it as name
+
+    if (res.express_redis_cache_name) {
+      name = res.express_redis_cache_name;
+    }
+
+    // If route() was called with a string as its first argument, use this string as name
+
+    if (typeof options[0] === "string") {
+      name = options[0];
+    }
+
+    if (typeof options[0] === "object" && typeof options[0].name === "string") {
+      name = options[0].name;
+    }
+
+    /** Name cannot have wildcards in them */
+
+    if (/\*/.test(name)) {
+      return next(new Error("Name can not have wildcards"));
+    }
+
+    /** The seconds entry lives
+     *
+     *  @type Number
+     *  @default this.expire
+     */
+    var expire = self.expire;
+    if (typeof options[0] === "object") {
+      if (
+        typeof options[0].expire === "number" ||
+        typeof options[0].expire === "object" ||
+        typeof options[0].expire === "function"
+      ) {
+        expire = options[0].expire;
+      }
+    }
+
+    if (typeof options[0] === "number") {
+      expire = options[0];
+    } else if (
+      typeof options[1] === "number" ||
+      typeof options[1] === "object"
+    ) {
+      expire = options[1];
+    }
+
+    var binary = false;
+    if (
+      typeof options[0] === "object" &&
+      typeof options[0].binary === "boolean"
+    ) {
+      binary = options[0].binary;
+    }
+
+    var expirationPolicy = Expire(expire);
+
+    /** attempt to get cache **/
+    self.get(name, function(error, cache) {
+      /** If there was an error with cache then call next **/
+
+      if (error) {
+        return next();
+      }
+
+      /** if it's cached, display cache **/
+
+      if (cache.length && cache[0].body != null) {
+        res.contentType(cache[0].type || "text/html");
+        if (binary) {
+          //Convert back to binary buffer
+          res.send(new Buffer.from(cache[0].body).toString("base64"));
+        } else {
+          res.send(cache[0].body);
+        }
+      } else {
+        /** otherwise, cache request **/
+        /** wrap res.send **/
+        var send = res.send.bind(res);
+
+        res.send = function(body) {
+          /** send output to HTTP client **/
+          var ret = send(body);
+
+          /** convert binary to base64 string **/
+          if (binary && typeof body !== "string") {
+            body = new Buffer.from(body).toString("base64");
+          }
+
+          /** save only strings to cache **/
+          if (typeof body !== "string") {
+            return ret;
+          }
+
+          /** Create the new cache **/
+          self.add(
+            name,
+            body,
+            {
+              type: this._headers["content-type"],
+              expire: expirationPolicy(req, res)
+            },
+            function (name, cache) {}); // eslint-disable-line
+
+          return ret;
+        };
+
+        return next();
+      }
+    });
+  };
+}
+
+export default route;
+
+
+
+ + + + +
+ +
+ +
+ Generated by JSDoc 3.5.5 on Fri Aug 10 2018 14:37:11 GMT+0200 (CEST) using the Minami theme. +
+ + + + + diff --git a/docs/express-redis-cache/2.0.0/ExpressRedisCache_size.js.html b/docs/express-redis-cache/2.0.0/ExpressRedisCache_size.js.html new file mode 100644 index 0000000..c7b5bdd --- /dev/null +++ b/docs/express-redis-cache/2.0.0/ExpressRedisCache_size.js.html @@ -0,0 +1,92 @@ + + + + + + ExpressRedisCache/size.js - Documentation + + + + + + + + + + + + + + + + + +
+ +

ExpressRedisCache/size.js

+ + + + + + + +
+
+
import async from "async";
+import sizeOf from "../sizeof";
+
+export default function(
+  /* Function */ callback // Callback
+) {
+  /** set in /index.js **/
+  var self = this;
+
+  /** Tell Redis to fetch the keys name beginning by prefix **/
+  self.client.keys(self.prefix + "*", function(err, keys) {
+    var size = 0;
+
+    async.parallel(
+      /** for each keys **/
+
+      keys.map(function(key) {
+        return function(cb) {
+          self.get(this.key.replace(new RegExp("^" + self.prefix), ""), cb);
+        }.bind({ key: key });
+      }),
+
+      function(results) {
+        results.forEach(function(result) {
+          size += sizeOf(result);
+        });
+
+        callback(null, size);
+      }
+    );
+  });
+}
+
+
+
+ + + + +
+ +
+ +
+ Generated by JSDoc 3.5.5 on Fri Aug 10 2018 14:37:11 GMT+0200 (CEST) using the Minami theme. +
+ + + + + diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-Bold-webfont.eot b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Bold-webfont.eot new file mode 100644 index 0000000..5d20d91 Binary files /dev/null and b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Bold-webfont.eot differ diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-Bold-webfont.svg b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Bold-webfont.svg new file mode 100644 index 0000000..3ed7be4 --- /dev/null +++ b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Bold-webfont.svg @@ -0,0 +1,1830 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-Bold-webfont.woff b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Bold-webfont.woff new file mode 100644 index 0000000..1205787 Binary files /dev/null and b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Bold-webfont.woff differ diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-BoldItalic-webfont.eot b/docs/express-redis-cache/2.0.0/fonts/OpenSans-BoldItalic-webfont.eot new file mode 100644 index 0000000..1f639a1 Binary files /dev/null and b/docs/express-redis-cache/2.0.0/fonts/OpenSans-BoldItalic-webfont.eot differ diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-BoldItalic-webfont.svg b/docs/express-redis-cache/2.0.0/fonts/OpenSans-BoldItalic-webfont.svg new file mode 100644 index 0000000..6a2607b --- /dev/null +++ b/docs/express-redis-cache/2.0.0/fonts/OpenSans-BoldItalic-webfont.svg @@ -0,0 +1,1830 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-BoldItalic-webfont.woff b/docs/express-redis-cache/2.0.0/fonts/OpenSans-BoldItalic-webfont.woff new file mode 100644 index 0000000..ed760c0 Binary files /dev/null and b/docs/express-redis-cache/2.0.0/fonts/OpenSans-BoldItalic-webfont.woff differ diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-Italic-webfont.eot b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Italic-webfont.eot new file mode 100644 index 0000000..0c8a0ae Binary files /dev/null and b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Italic-webfont.eot differ diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-Italic-webfont.svg b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Italic-webfont.svg new file mode 100644 index 0000000..e1075dc --- /dev/null +++ b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Italic-webfont.svg @@ -0,0 +1,1830 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-Italic-webfont.woff b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Italic-webfont.woff new file mode 100644 index 0000000..ff652e6 Binary files /dev/null and b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Italic-webfont.woff differ diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-Light-webfont.eot b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Light-webfont.eot new file mode 100644 index 0000000..1486840 Binary files /dev/null and b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Light-webfont.eot differ diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-Light-webfont.svg b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Light-webfont.svg new file mode 100644 index 0000000..11a472c --- /dev/null +++ b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Light-webfont.svg @@ -0,0 +1,1831 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-Light-webfont.woff b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Light-webfont.woff new file mode 100644 index 0000000..e786074 Binary files /dev/null and b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Light-webfont.woff differ diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-LightItalic-webfont.eot b/docs/express-redis-cache/2.0.0/fonts/OpenSans-LightItalic-webfont.eot new file mode 100644 index 0000000..8f44592 Binary files /dev/null and b/docs/express-redis-cache/2.0.0/fonts/OpenSans-LightItalic-webfont.eot differ diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-LightItalic-webfont.svg b/docs/express-redis-cache/2.0.0/fonts/OpenSans-LightItalic-webfont.svg new file mode 100644 index 0000000..431d7e3 --- /dev/null +++ b/docs/express-redis-cache/2.0.0/fonts/OpenSans-LightItalic-webfont.svg @@ -0,0 +1,1835 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-LightItalic-webfont.woff b/docs/express-redis-cache/2.0.0/fonts/OpenSans-LightItalic-webfont.woff new file mode 100644 index 0000000..43e8b9e Binary files /dev/null and b/docs/express-redis-cache/2.0.0/fonts/OpenSans-LightItalic-webfont.woff differ diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-Regular-webfont.eot b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Regular-webfont.eot new file mode 100644 index 0000000..6bbc3cf Binary files /dev/null and b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Regular-webfont.eot differ diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-Regular-webfont.svg b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Regular-webfont.svg new file mode 100644 index 0000000..25a3952 --- /dev/null +++ b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Regular-webfont.svg @@ -0,0 +1,1831 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-Regular-webfont.woff b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Regular-webfont.woff new file mode 100644 index 0000000..e231183 Binary files /dev/null and b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Regular-webfont.woff differ diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-Semibold-webfont.eot b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Semibold-webfont.eot new file mode 100644 index 0000000..d8375dd Binary files /dev/null and b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Semibold-webfont.eot differ diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-Semibold-webfont.svg b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Semibold-webfont.svg new file mode 100644 index 0000000..eec4db8 --- /dev/null +++ b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Semibold-webfont.svg @@ -0,0 +1,1830 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-Semibold-webfont.ttf b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Semibold-webfont.ttf new file mode 100644 index 0000000..b329084 Binary files /dev/null and b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Semibold-webfont.ttf differ diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-Semibold-webfont.woff b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Semibold-webfont.woff new file mode 100644 index 0000000..28d6ade Binary files /dev/null and b/docs/express-redis-cache/2.0.0/fonts/OpenSans-Semibold-webfont.woff differ diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-SemiboldItalic-webfont.eot b/docs/express-redis-cache/2.0.0/fonts/OpenSans-SemiboldItalic-webfont.eot new file mode 100644 index 0000000..0ab1db2 Binary files /dev/null and b/docs/express-redis-cache/2.0.0/fonts/OpenSans-SemiboldItalic-webfont.eot differ diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-SemiboldItalic-webfont.svg b/docs/express-redis-cache/2.0.0/fonts/OpenSans-SemiboldItalic-webfont.svg new file mode 100644 index 0000000..7166ec1 --- /dev/null +++ b/docs/express-redis-cache/2.0.0/fonts/OpenSans-SemiboldItalic-webfont.svg @@ -0,0 +1,1830 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-SemiboldItalic-webfont.ttf b/docs/express-redis-cache/2.0.0/fonts/OpenSans-SemiboldItalic-webfont.ttf new file mode 100644 index 0000000..d2d6318 Binary files /dev/null and b/docs/express-redis-cache/2.0.0/fonts/OpenSans-SemiboldItalic-webfont.ttf differ diff --git a/docs/express-redis-cache/2.0.0/fonts/OpenSans-SemiboldItalic-webfont.woff b/docs/express-redis-cache/2.0.0/fonts/OpenSans-SemiboldItalic-webfont.woff new file mode 100644 index 0000000..d4dfca4 Binary files /dev/null and b/docs/express-redis-cache/2.0.0/fonts/OpenSans-SemiboldItalic-webfont.woff differ diff --git a/docs/express-redis-cache/2.0.0/global.html b/docs/express-redis-cache/2.0.0/global.html new file mode 100644 index 0000000..3e764bd --- /dev/null +++ b/docs/express-redis-cache/2.0.0/global.html @@ -0,0 +1,266 @@ + + + + + + Global - Documentation + + + + + + + + + + + + + + + + + +
+ +

Global

+ + + + + + + +
+ +
+ +

+ +

+ + +
+ +
+
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + +

Type Definitions

+ + + +
+

add

+ + + + +
+

Add a new cache entry

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + +
+ + + +
+

get

+ + + + +
+

Get

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + +
+ + + + + +
+ +
+ + + + +
+ +
+ +
+ Generated by JSDoc 3.5.5 on Fri Aug 10 2018 14:37:11 GMT+0200 (CEST) using the Minami theme. +
+ + + + + \ No newline at end of file diff --git a/docs/express-redis-cache/2.0.0/index.html b/docs/express-redis-cache/2.0.0/index.html new file mode 100644 index 0000000..c42b018 --- /dev/null +++ b/docs/express-redis-cache/2.0.0/index.html @@ -0,0 +1,309 @@ + + + + + + Home - Documentation + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+

express-redis-cache

Build Status +dependencies Status

+

Easily cache pages of your app using Express and Redis. Could be used without Express too.

+

Install

npm install express-redis-cache

express-redis-cache ships with a CLI utility you can invoke from the console. In order to use it, install express-redis-cache globally (might require super user privileges):

+
npm install -g express-redis-cache

Upgrade

Read this if you are upgrading from 0.0.8 to 0.1.x,

+

Usage

Just use it as a middleware in the stack of the route you want to cache.

+
var app = express();
+var cache = require('express-redis-cache')();
+
+// replace
+app.get('/',
+  function (req, res)  { ... });
+
+// by
+app.get('/',
+  cache.route(),
+  function (req, res)  { ... });

This will check if there is a cache entry for this route. If not. it will cache it and serve the cache next time route is called.

+

Redis connection info

By default, redis-express-cache connects to Redis using localhost as host and nothing as port (using Redis default port 6379). To use different port or host, declare them when you require express-redis-cache. If your Redis server requires password, use the auth_pass option.

+
var cache = require('express-redis-cache')({
+  host: String, port: Number, auth_pass: REDIS_PASSWORD
+  });

You can pass a Redis client as well:

+
require('express-redis-cache')({ client: require('redis').createClient() })

You can have several clients if you want to serve from more than one Redis server:

+
var cache = require('express-redis-cache');
+var client1 = cache({ host: "...", port: "..." });
+var client2 = cache({ host: "...", port: "..." });
+...

Redis Unavailability

Should the redis become unavailable, the express-redis-cache object will emit errors but will not crash the app. Express.js requests during this time will be bypass cache and will return fresh data.

+

Once the redis recovers, the caching will begin working again. See example code in the /example folder.

+

Name of the cache entry

By default, the cache entry name will be default prefix:name where name's value defaults to req.originalUrl.

+
app.get('/',
+  cache.route(), // cache entry name is `cache.prefix + "/"`
+  function (req, res)  { ... });

You can specify a custom name like this:

+
app.get('/',
+  cache.route('home'), // cache entry name is now `cache.prefix + "home"`
+  function (req, res)  { ... });

You can also use the object syntax:

+
app.get('/',
+  cache.route({ name: 'home' }), // cache entry name is `cache.prefix + "home"`
+  function (req, res)  { ... });

Also, you can use res.express_redis_cache_name to specify the name of the entry such as:

+
app.get('/user/:userid',
+
+  // middleware to define cache name
+
+  function (req, res, next) {
+    // set cache name
+    res.express_redis_cache_name = 'user-' + req.params.userid;
+    next();
+    },
+
+  // cache middleware
+
+  cache.route(),
+
+  // content middleware
+
+  function (req, res) {
+    res.render('user');
+    }
+
+  );

Conditional caching

You can also use a previous middleware to set whether or not to use the cache by using res.use_express_redis_cache:

+

+app.get('/user',
+
+  // middleware to decide if using cache
+
+  function (req, res, next) {
+    // Use only cache if user not signed in
+    res.use_express_redis_cache = ! req.signedCookies.user;
+
+    next();
+    }.
+
+  cache.route(), // this will be skipped if user is signed in
+
+  function (req, res) {
+    res.render('user');
+    }
+  );

Prefix

All entry names are prepended by a prefix. Prefix is set when calling the Constructor.

+
// Set default prefix to "test". All entry names will begin by "test:"
+var cache = require('express-redis-cache')({ prefix: 'test' });

To know the prefix:

+
console.log('prefix', cache.prefix);

You can pass a custom prefix when calling route():

+
app.get('/index.html',
+  cache.route('index', { prefix: 'test'  }), // force prefix to be "test", entry name will be "test:index"
+  function (req, res)  { ... });

You can also choose not to use prefixes:

+
app.get('/index.html',
+  cache.route({ prefix: false  }), // no prefixing, entry name will be "/index.html"
+  function (req, res)  { ... });

Expiration

Unless specified otherwise when calling the Constructor, cache entries don't expire. You can specify a default lifetime when calling the constructor:

+
// Set default lifetime to 60 seconds for all entries
+var cache = require('express-redis-cache')({ expire: 60 });

You can overwrite the default lifetime when calling route():

+
app.get('/index.html',
+  cache.route({ expire: 5000  }), // cache entry will live 5000 seconds
+  function (req, res)  { ... });
+
+// You can also use the number sugar syntax
+cache.route(5000);
+// Or
+cache.route('index', 5000);
+// Or
+cache.route({ prefix: 'test' }, 5000);

You can also provide a hash of status code / expiration values if you for example want to retry much sooner in failure cases (403/404/500/etc). Status ranges can be specified via 4xx/5xx. You must provide a default value (xxx). The most specific rule will be used. For example, if the status code is 200, and there are expirations set for 200, 2xx, and xxx, the expiration for 200 will be used.

+
app.get('/index.html',
+  cache.route({
+    expire: {
+      200: 5000,
+      4xx: 10,
+      403: 5000,
+      5xx: 10,
+      xxx: 1
+    }
+  }),
+  function (req, res)  { ... });

You can also specify

+

Content Type

You can use express-redis-cache to cache HTML pages, CSS stylesheets, JSON objects, anything really. Content-types are saved along the cache body and are retrieved using res._headers['content-type']. If you want to overwrite that, you can pass a custom type.

+
app.get('/index.html',
+  cache.route({ type: 'text/plain'  }), // force entry type to be "text/plain"
+  function (req, res)  { ... });

Events

The module emits the following events:

+

error

You can catch errors by adding a listener:

+
cache.on('error', function (error) {
+  throw new Error('Cache error!');
+});

message

express-redis-cache logs some information at runtime. You can access it like this:

+
cache.on('message', function (message) {
+  // ...
+});

connected

Emitted when the client is connected (or re-connected) to Redis server

+
cache.on('connected', function () {
+  // ....
+});

disconnected

Emitted when the client is disconnected from Redis server. When (and if) it reconnects, it will emit a 'connected' event again

+
cache.on('disconnected', function () {
+  // ....
+});

Note You can get the connexion status at any time by getting the property cache.connected which returns a boolean (true = connected, false = disconnected).

+

deprecated

Warning emitted when stumbled upon a deprecated part of the code

+
cache.on('deprecated', function (deprecated) {
+  console.log('deprecated warning', {
+      type: deprecated.type,
+      name: deprecated.name,
+      substitute: deprecated.substitute,
+      file: deprecated.file,
+      line: deprecated.line
+  });
+});

The Entry Model

This is the object synopsis we use to represent a cache entry:

+
var entry = {
+  body:    String // the content of the cache
+  touched: Number // last time cache was set (created or updated) as a Unix timestamp
+  expire:  Number // the seconds cache entry lives (-1 if does not expire)
+  type: String // the content-type
+};

The module

The module exposes a function which instantiates a new instance of a class called ExpressRedisCache.

+
// This
+var cache = require('express-redis-cache')({ /* ... */ });
+// is the same than
+var cache = new (require('express-redis-cache/lib/ExpressRedisCache'))({ /* ... */ });

The constructor

As stated above, call the function exposed by the module to create a new instance of ExpressRedisCache,

+
var cache = require('express-redis-cache')(/** Object | Undefined */ options);

Where options is an object that has the following properties:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OptionTypeDefaultDescription
hostStringundefinedRedis server host
portNumberundefinedRedis server port
prefixStringrequire('express-redis-cache/package.json').config.prefixDefault prefix (This will be prepended to all entry names)
expireNumberundefinedDefault life time of entries in seconds
clientRedisClientrequire('redis').createClient({ host: cache.host, port: cache.port })A Redis client
+

API

The route method is designed to integrate easily with Express. You can also define your own caching logics using the other methos of the API shown below.

+

get Get cache entries

cache.get(/** Mixed (optional) */ query, /** Function( Error, [Entry] ) */ callback );

To get all cache entries:

+
cache.get(function (error, entries) {
+  if ( error ) throw error;
+
+  entries.forEach(console.log.bind(console));
+});

To get a specific entry:

+
cache.get('home', function (error, entries) {});

To get a specific entry for a given prefix:

+
cache.get({ name: 'home', prefix: 'test' }, function (error, entries) {});

You can use wildcard:

+
cache.get('user*', function (error, entries) {});

add Add a new cache entry

cache.add(/** String */ name, /** String */ body, /** Object (optional) **/ options, /** Function( Error, Entry ) */ callback )

Where options is an object that can have the following properties:

+
    +
  • expire Number (lifetime of entry in seconds)
  • +
  • type String (the content-type)
  • +
+

Example:

+
cache.add('user:info', JSON.stringify({ id: 1, email: 'john@doe.com' }), { expire: 60 * 60 * 24, type: 'json' },
+    function (error, added) {});

del Delete a cache entry

cache.del(/** String */ name, /** Function ( Error, Number deletions ) */ callback);

You can use wildcard (*) in name.

+

size Get cache size for all entries

cache.size(/** Function ( Error, Number bytes ) */);

Command line

We ship with a CLI. You can invoke it like this: express-redis-cache

+

View cache entries

express-redis-cache ls

Add cache entry

express-redis-cache add $name $body $expire --type $type

Examples

# Cache simple text
+express-redis-cache add "test" "This is a test";
+
+# Cache a file
+express-redis-cache add "home" "$(cat index.html)";
+
+# Cache a JSON object
+express-redis-cache add "user1:location" '{ "lat": 4.7453, "lng": -31.332 }' --type json;
+
+# Cache a text that will expire in one hour
+express-redis-cache add "offer" "everything 25% off for the next hour" $(( 60 * 60 ));

Get single cache entry

express-redis-cache get $name
+# Example: express-redis-cache get user1:*
+# Output:

Delete cache entry

express-redis-cache del $name
+# Example: express-redis-cache del user1:*
+# Output:

Get total cache size

express-redis-cache size
+# Output:

Example Code

Run the example to see how the caching behaves. You can kill the redis-server and the application will respond with non-cached information.

+
npm install
+cd example
+node example.js

Test

We use Mocha and Should for the tests. You can invoke tests like this:

+
npm test

Test environments

You can specify the following environments before running your tests:

+
export EX_RE_CA_HOST="";
+export EX_RE_CA_PORT="";
+export EX_RE_CA_PREFIX="";

Contributors

+
+

Enjoy!

+
+ + + + + + +
+ +
+ +
+ Generated by JSDoc 3.5.5 on Fri Aug 10 2018 14:37:11 GMT+0200 (CEST) using the Minami theme. +
+ + + + + \ No newline at end of file diff --git a/docs/express-redis-cache/2.0.0/index.js.html b/docs/express-redis-cache/2.0.0/index.js.html new file mode 100644 index 0000000..ff05d54 --- /dev/null +++ b/docs/express-redis-cache/2.0.0/index.js.html @@ -0,0 +1,225 @@ + + + + + + index.js - Documentation + + + + + + + + + + + + + + + + + +
+ +

index.js

+ + + + + + + +
+
+
import { EventEmitter } from "events";
+import redis from "redis";
+import Get from "./ExpressRedisCache/get";
+import Add from "./ExpressRedisCache/add";
+import Del from "./ExpressRedisCache/del";
+import Route from "./ExpressRedisCache/route";
+import Size from "./ExpressRedisCache/size";
+import { config } from "../package.json";
+
+/**  ExpressRedisCache
+ *
+ *  @class
+ *  @description Main class
+ *  @extends EventEmitter
+ *  @arg {Object} options? - Options (view README)
+ */
+
+class ExpressRedisCache extends EventEmitter {
+  constructor(options) {
+    super(options);
+
+    /** The request options
+     *
+     *  @type Object
+     */
+
+    this.options = options || {};
+
+    /** The entry name prefix
+     *
+     *  @type String
+     */
+
+    this.prefix = this.options.prefix || config.prefix;
+
+    /** The host to connect to (default host if null)
+     *
+     *  @type String
+     */
+
+    this.host = this.options.host || "localhost";
+
+    /** The port to connect to (default port if null)
+     *
+     *  @type Number
+     */
+
+    this.port = this.options.port || "6379";
+
+    /** The password of Redis server (optional)
+     *
+     *  @type String
+     */
+    this.auth_pass = this.options.auth_pass;
+
+    /** An alias to disable expiration for a specific route
+     *
+     *  var cache = new ExpressRedisCache();
+     *  cache.route('page', cache.FOREVER); // cache will not expire
+     *
+     *  @type number
+     */
+
+    this.FOREVER = -1;
+
+    /** Set expiration time in seconds, default is -1 (No expire)
+     *  @type number
+     */
+
+    this.expire = this.options.expire || this.FOREVER;
+
+    /** Whether or not express-redis-cache is connected to Redis
+     *
+     *  @type Boolean
+     */
+
+    this.connected = false;
+
+    /** The Redis Client
+     *
+     *  @type Object
+     */
+
+    this.client =
+      this.options.client ||
+      redis.createClient(this.port, this.host, { auth_pass: this.auth_pass });
+
+    /** If client can emit */
+
+    if (this.client.on) {
+      this.client.on("error", error => {
+        console.error(error);
+        this.connected = false;
+        this.emit("message", "Redis is unavailable or not running");
+      });
+
+      this.client.on("connect", () => {
+        this.connected = true;
+        this.emit("connected", { host: this.host, port: this.port });
+        this.emit("message", `OK connected to redis://${this.client.address}`);
+      });
+
+      this.client.on("end", () => {
+        this.connected = false;
+        this.emit("disconnected", { host: this.host, port: this.port });
+        this.emit(
+          "message",
+          `Disconnected from redis://${this.client.host}:${this.client.port}`
+        );
+      });
+    }
+
+    /**  js-comment
+     *
+     *  @method
+     *  @description Get -
+     *  @return void{Object}
+     *  @arg {Object} arg - About arg
+     */
+
+    this.get = Get;
+
+    /**  js-comment
+     *
+     *  @method
+     *  @description This is a method
+     *  @return void{Object}
+     *  @arg {Object} arg - About arg
+     */
+
+    this.add = Add;
+
+    /**  js-comment
+     *
+     *  @method
+     *  @description This is a method
+     *  @return void{Object}
+     *  @arg {Object} arg - About arg
+     */
+
+    this.del = Del;
+
+    /**  js-comment
+     *
+     *  @method
+     *  @description This is a method
+     *  @return void{Object}
+     *  @arg {Object} arg - About arg
+     */
+
+    this.route = Route;
+
+    /**  js-comment
+     *
+     *  @method
+     *  @description This is a method
+     *  @return void{Object}
+     *  @arg {Object} arg - About arg
+     */
+
+    this.size = Size;
+  }
+}
+
+export default ExpressRedisCache;
+
+
+
+ + + + +
+ +
+ +
+ Generated by JSDoc 3.5.5 on Fri Aug 10 2018 14:37:11 GMT+0200 (CEST) using the Minami theme. +
+ + + + + diff --git a/docs/express-redis-cache/2.0.0/scripts/linenumber.js b/docs/express-redis-cache/2.0.0/scripts/linenumber.js new file mode 100644 index 0000000..8d52f7e --- /dev/null +++ b/docs/express-redis-cache/2.0.0/scripts/linenumber.js @@ -0,0 +1,25 @@ +/*global document */ +(function() { + var source = document.getElementsByClassName('prettyprint source linenums'); + var i = 0; + var lineNumber = 0; + var lineId; + var lines; + var totalLines; + var anchorHash; + + if (source && source[0]) { + anchorHash = document.location.hash.substring(1); + lines = source[0].getElementsByTagName('li'); + totalLines = lines.length; + + for (; i < totalLines; i++) { + lineNumber++; + lineId = 'line' + lineNumber; + lines[i].id = lineId; + if (lineId === anchorHash) { + lines[i].className += ' selected'; + } + } + } +})(); diff --git a/docs/express-redis-cache/2.0.0/scripts/prettify/Apache-License-2.0.txt b/docs/express-redis-cache/2.0.0/scripts/prettify/Apache-License-2.0.txt new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/docs/express-redis-cache/2.0.0/scripts/prettify/Apache-License-2.0.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/docs/express-redis-cache/2.0.0/scripts/prettify/lang-css.js b/docs/express-redis-cache/2.0.0/scripts/prettify/lang-css.js new file mode 100644 index 0000000..041e1f5 --- /dev/null +++ b/docs/express-redis-cache/2.0.0/scripts/prettify/lang-css.js @@ -0,0 +1,2 @@ +PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", +/^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); diff --git a/docs/express-redis-cache/2.0.0/scripts/prettify/prettify.js b/docs/express-redis-cache/2.0.0/scripts/prettify/prettify.js new file mode 100644 index 0000000..eef5ad7 --- /dev/null +++ b/docs/express-redis-cache/2.0.0/scripts/prettify/prettify.js @@ -0,0 +1,28 @@ +var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; +(function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= +[],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), +l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, +q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, +q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, +"");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), +a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} +for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], +"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], +H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], +J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ +I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), +["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", +/^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), +["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", +hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= +!k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p code { + font-size: 0.85em; +} + +.readme table { + margin-bottom: 1em; + border-collapse: collapse; + border-spacing: 0; +} + +.readme table tr { + background-color: #fff; + border-top: 1px solid #ccc; +} + +.readme table th, +.readme table td { + padding: 6px 13px; + border: 1px solid #ddd; +} + +.readme table tr:nth-child(2n) { + background-color: #f8f8f8; +} + +/** Nav **/ +nav { + float: left; + display: block; + width: 250px; + background: #fff; + overflow: auto; + position: fixed; + height: 100%; + padding: 10px; + border-right: 1px solid #eee; + /* box-shadow: 0 0 3px rgba(0,0,0,0.1); */ +} + +nav li { + list-style: none; + padding: 0; + margin: 0; +} + +.nav-heading { + margin-top: 10px; + font-weight: bold; +} + +.nav-heading a { + color: #888; + font-size: 14px; + display: inline-block; +} + +.nav-item-type { + /* margin-left: 5px; */ + width: 18px; + height: 18px; + display: inline-block; + text-align: center; + border-radius: 0.2em; + margin-right: 5px; + font-weight: bold; + line-height: 20px; + font-size: 13px; +} + +.type-function { + background: #B3E5FC; + color: #0288D1; +} + +.type-class { + background: #D1C4E9; + color: #4527A0; +} + +.type-member { + background: #C8E6C9; + color: #388E3C; +} + +.type-module { + background: #E1BEE7; + color: #7B1FA2; +} + + +/** Footer **/ +footer { + color: hsl(0, 0%, 28%); + margin-left: 250px; + display: block; + padding: 30px; + font-style: italic; + font-size: 90%; + border-top: 1px solid #eee; +} + +.ancestors { + color: #999 +} + +.ancestors a { + color: #999 !important; + text-decoration: none; +} + +.clear { + clear: both +} + +.important { + font-weight: bold; + color: #950B02; +} + +.yes-def { + text-indent: -1000px +} + +.type-signature { + color: #aaa +} + +.name, .signature { + font-family: Consolas, Monaco, 'Andale Mono', monospace +} + +.details { + margin-top: 14px; + border-left: 2px solid #DDD; + line-height: 30px; +} + +.details dt { + width: 120px; + float: left; + padding-left: 10px; +} + +.details dd { + margin-left: 70px +} + +.details ul { + margin: 0 +} + +.details ul { + list-style-type: none +} + +.details li { + margin-left: 30px +} + +.details pre.prettyprint { + margin: 0 +} + +.details .object-value { + padding-top: 0 +} + +.description { + margin-bottom: 1em; + margin-top: 1em; +} + +.code-caption { + font-style: italic; + font-size: 107%; + margin: 0; +} + +.prettyprint { + font-size: 13px; + border: 1px solid #ddd; + border-radius: 3px; + box-shadow: 0 1px 3px hsla(0, 0%, 0%, 0.05); + overflow: auto; +} + +.prettyprint.source { + width: inherit +} + +.prettyprint code { + font-size: 12px; + line-height: 18px; + display: block; + background-color: #fff; + color: #4D4E53; +} + +.prettyprint code:empty:before { + content: ''; +} + +.prettyprint > code { + padding: 15px +} + +.prettyprint .linenums code { + padding: 0 15px +} + +.prettyprint .linenums li:first-of-type code { + padding-top: 15px +} + +.prettyprint code span.line { + display: inline-block +} + +.prettyprint.linenums { + padding-left: 70px; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + +.prettyprint.linenums ol { + padding-left: 0 +} + +.prettyprint.linenums li { + border-left: 3px #ddd solid +} + +.prettyprint.linenums li.selected, .prettyprint.linenums li.selected * { + background-color: lightyellow +} + +.prettyprint.linenums li * { + -webkit-user-select: text; + -moz-user-select: text; + -ms-user-select: text; + user-select: text; +} + +.params, .props { + border-spacing: 0; + border: 1px solid #ddd; + border-collapse: collapse; + border-radius: 3px; + box-shadow: 0 1px 3px rgba(0,0,0,0.1); + width: 100%; + font-size: 14px; + /* margin-left: 15px; */ +} + +.params .name, .props .name, .name code { + color: #4D4E53; + font-family: Consolas, Monaco, 'Andale Mono', monospace; + font-size: 100%; +} + +.params td, .params th, .props td, .props th { + margin: 0px; + text-align: left; + vertical-align: top; + padding: 10px; + display: table-cell; +} + +.params td { + border-top: 1px solid #eee +} + +.params thead tr, .props thead tr { + background-color: #fff; + font-weight: bold; +} + +.params .params thead tr, .props .props thead tr { + background-color: #fff; + font-weight: bold; +} + +.params td.description > p:first-child, .props td.description > p:first-child { + margin-top: 0; + padding-top: 0; +} + +.params td.description > p:last-child, .props td.description > p:last-child { + margin-bottom: 0; + padding-bottom: 0; +} + +dl.param-type { + /* border-bottom: 1px solid hsl(0, 0%, 87%); */ + margin: 0; + padding: 0; + font-size: 16px; +} + +.param-type dt, .param-type dd { + display: inline-block +} + +.param-type dd { + font-family: Consolas, Monaco, 'Andale Mono', monospace; + display: inline-block; + padding: 0; + margin: 0; + font-size: 14px; +} + +.disabled { + color: #454545 +} + +/* navicon button */ +.navicon-button { + display: none; + position: relative; + padding: 2.0625rem 1.5rem; + transition: 0.25s; + cursor: pointer; + user-select: none; + opacity: .8; +} +.navicon-button .navicon:before, .navicon-button .navicon:after { + transition: 0.25s; +} +.navicon-button:hover { + transition: 0.5s; + opacity: 1; +} +.navicon-button:hover .navicon:before, .navicon-button:hover .navicon:after { + transition: 0.25s; +} +.navicon-button:hover .navicon:before { + top: .825rem; +} +.navicon-button:hover .navicon:after { + top: -.825rem; +} + +/* navicon */ +.navicon { + position: relative; + width: 2.5em; + height: .3125rem; + background: #000; + transition: 0.3s; + border-radius: 2.5rem; +} +.navicon:before, .navicon:after { + display: block; + content: ""; + height: .3125rem; + width: 2.5rem; + background: #000; + position: absolute; + z-index: -1; + transition: 0.3s 0.25s; + border-radius: 1rem; +} +.navicon:before { + top: .625rem; +} +.navicon:after { + top: -.625rem; +} + +/* open */ +.nav-trigger:checked + label:not(.steps) .navicon:before, +.nav-trigger:checked + label:not(.steps) .navicon:after { + top: 0 !important; +} + +.nav-trigger:checked + label .navicon:before, +.nav-trigger:checked + label .navicon:after { + transition: 0.5s; +} + +/* Minus */ +.nav-trigger:checked + label { + transform: scale(0.75); +} + +/* × and + */ +.nav-trigger:checked + label.plus .navicon, +.nav-trigger:checked + label.x .navicon { + background: transparent; +} + +.nav-trigger:checked + label.plus .navicon:before, +.nav-trigger:checked + label.x .navicon:before { + transform: rotate(-45deg); + background: #FFF; +} + +.nav-trigger:checked + label.plus .navicon:after, +.nav-trigger:checked + label.x .navicon:after { + transform: rotate(45deg); + background: #FFF; +} + +.nav-trigger:checked + label.plus { + transform: scale(0.75) rotate(45deg); +} + +.nav-trigger:checked ~ nav { + left: 0 !important; +} + +.nav-trigger:checked ~ .overlay { + display: block; +} + +.nav-trigger { + position: fixed; + top: 0; + clip: rect(0, 0, 0, 0); +} + +.overlay { + display: none; + position: fixed; + top: 0; + bottom: 0; + left: 0; + right: 0; + width: 100%; + height: 100%; + background: hsla(0, 0%, 0%, 0.5); + z-index: 1; +} + +.section-method { + margin-bottom: 30px; + padding-bottom: 30px; + border-bottom: 1px solid #eee; +} + +@media only screen and (min-width: 320px) and (max-width: 680px) { + body { + overflow-x: hidden; + } + + nav { + background: #FFF; + width: 250px; + height: 100%; + position: fixed; + top: 0; + right: 0; + bottom: 0; + left: -250px; + z-index: 3; + padding: 0 10px; + transition: left 0.2s; + } + + .navicon-button { + display: inline-block; + position: fixed; + top: 1.5em; + right: 0; + z-index: 2; + } + + #main { + width: 100%; + min-width: 360px; + } + + #main h1.page-title { + margin: 1em 0; + } + + #main section { + padding: 0; + } + + footer { + margin-left: 0; + } +} + +@media only print { + nav { + display: none; + } + + #main { + float: none; + width: 100%; + } +} diff --git a/docs/express-redis-cache/2.0.0/styles/prettify-jsdoc.css b/docs/express-redis-cache/2.0.0/styles/prettify-jsdoc.css new file mode 100644 index 0000000..834a866 --- /dev/null +++ b/docs/express-redis-cache/2.0.0/styles/prettify-jsdoc.css @@ -0,0 +1,111 @@ +/* JSDoc prettify.js theme */ + +/* plain text */ +.pln { + color: #000000; + font-weight: normal; + font-style: normal; +} + +/* string content */ +.str { + color: hsl(104, 100%, 24%); + font-weight: normal; + font-style: normal; +} + +/* a keyword */ +.kwd { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* a comment */ +.com { + font-weight: normal; + font-style: italic; +} + +/* a type name */ +.typ { + color: #000000; + font-weight: normal; + font-style: normal; +} + +/* a literal value */ +.lit { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* punctuation */ +.pun { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* lisp open bracket */ +.opn { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* lisp close bracket */ +.clo { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* a markup tag name */ +.tag { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* a markup attribute name */ +.atn { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* a markup attribute value */ +.atv { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* a declaration */ +.dec { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* a variable name */ +.var { + color: #000000; + font-weight: normal; + font-style: normal; +} + +/* a function name */ +.fun { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* Specify class=linenums on a pre to get line numbering */ +ol.linenums { + margin-top: 0; + margin-bottom: 0; +} diff --git a/docs/express-redis-cache/2.0.0/styles/prettify-tomorrow.css b/docs/express-redis-cache/2.0.0/styles/prettify-tomorrow.css new file mode 100644 index 0000000..81e74d1 --- /dev/null +++ b/docs/express-redis-cache/2.0.0/styles/prettify-tomorrow.css @@ -0,0 +1,132 @@ +/* Tomorrow Theme */ +/* Original theme - https://github.com/chriskempson/tomorrow-theme */ +/* Pretty printing styles. Used with prettify.js. */ +/* SPAN elements with the classes below are added by prettyprint. */ +/* plain text */ +.pln { + color: #4d4d4c; } + +@media screen { + /* string content */ + .str { + color: hsl(104, 100%, 24%); } + + /* a keyword */ + .kwd { + color: hsl(240, 100%, 50%); } + + /* a comment */ + .com { + color: hsl(0, 0%, 60%); } + + /* a type name */ + .typ { + color: hsl(240, 100%, 32%); } + + /* a literal value */ + .lit { + color: hsl(240, 100%, 40%); } + + /* punctuation */ + .pun { + color: #000000; } + + /* lisp open bracket */ + .opn { + color: #000000; } + + /* lisp close bracket */ + .clo { + color: #000000; } + + /* a markup tag name */ + .tag { + color: #c82829; } + + /* a markup attribute name */ + .atn { + color: #f5871f; } + + /* a markup attribute value */ + .atv { + color: #3e999f; } + + /* a declaration */ + .dec { + color: #f5871f; } + + /* a variable name */ + .var { + color: #c82829; } + + /* a function name */ + .fun { + color: #4271ae; } } +/* Use higher contrast and text-weight for printable form. */ +@media print, projection { + .str { + color: #060; } + + .kwd { + color: #006; + font-weight: bold; } + + .com { + color: #600; + font-style: italic; } + + .typ { + color: #404; + font-weight: bold; } + + .lit { + color: #044; } + + .pun, .opn, .clo { + color: #440; } + + .tag { + color: #006; + font-weight: bold; } + + .atn { + color: #404; } + + .atv { + color: #060; } } +/* Style */ +/* +pre.prettyprint { + background: white; + font-family: Consolas, Monaco, 'Andale Mono', monospace; + font-size: 12px; + line-height: 1.5; + border: 1px solid #ccc; + padding: 10px; } +*/ + +/* Specify class=linenums on a pre to get line numbering */ +ol.linenums { + margin-top: 0; + margin-bottom: 0; } + +/* IE indents via margin-left */ +li.L0, +li.L1, +li.L2, +li.L3, +li.L4, +li.L5, +li.L6, +li.L7, +li.L8, +li.L9 { + /* */ } + +/* Alternate shading for lines */ +li.L1, +li.L3, +li.L5, +li.L7, +li.L9 { + /* */ } diff --git a/example/example.js b/example/example.js index c31cafe..8454f07 100644 --- a/example/example.js +++ b/example/example.js @@ -1,27 +1,25 @@ -var app = require('express')(), - cache = require('../')({ expire: 5 }); +let app = require("express")(), + cache = require("../")({ expire: 5 }); -cache.on('message', function(message){ +cache.on("message", message => { console.log("cache", message); }); -cache.on('error', function(error){ +cache.on("error", error => { console.error("cache", error); }); -var port = 3000; +let port = 3000; app.listen(port); -console.log("Server listening on http://localhost:" + port); +console.log(`Server listening on http://localhost:${port}`); // Serve simple page with timestamp cached for 5 seconds -app.get('/:skip_cache?', - cache.route(), - function (req, res) { - if (req.params.skip_cache) { - res.use_express_redis_cache = false; - console.log ("Cache disabled on this request"); - } +app.get("/:skip_cache?", cache.route(), (req, res) => { + if (req.params.skip_cache) { + res.use_express_redis_cache = false; + console.log("Cache disabled on this request"); + } - var currTime = new Date(); - res.send("Date and time: " + currTime); -}); \ No newline at end of file + let currTime = new Date(); + res.send(`Date and time: ${currTime}`); +}); diff --git a/express/server.js b/express/server.js index e16faae..ef196ab 100755 --- a/express/server.js +++ b/express/server.js @@ -1,90 +1,83 @@ #!/usr/bin/env node -var path = require('path'); +let path = require("path"); +const ERC = require("../dist").default; /* ======== express ======== */ -var express = require('express'); -var app = express(); +let express = require("express"); +let app = express(); -app.set('port', process.env.PORT || 3027); +app.set("port", process.env.PORT || 3027); /* ======== cache ======== */ -var cache_options = { - expire : 3, - host : process.env.EX_RE_CA_HOST || 'localhost', - port : process.env.EX_RE_CA_PORT || 6379, - prefix : process.env.EX_RE_CA_PREFIX || 'erct:' +let cache_options = { + expire: 3, + host: process.env.EX_RE_CA_HOST || "localhost", + port: process.env.EX_RE_CA_PORT || 6379, + prefix: process.env.EX_RE_CA_PREFIX || "erct:" }; -var cache = require('../')(cache_options); -var moment = require('moment'); +let cache = new ERC(cache_options); +let moment = require("moment"); -cache.on('error', function (error) { - console.log('cache error', { +cache.on("error", error => { + console.log("cache error", { message: error.message }); }); /* ======== body parser ======== */ -var bodyParser = require('body-parser'); +let bodyParser = require("body-parser"); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); /* ======== home ======== */ -function handle_timestamp (req, res) { - res.set({'Content-Type': 'text/json'}); - var timestamp = { timestamp: moment().unix()}; +function handle_timestamp(req, res) { + res.set({ "Content-Type": "application/json" }); + let timestamp = { timestamp: moment().unix() }; return res.json(timestamp); } // Cache the time for 1 second as // { timestamp: 1424309866 } -app.all('/1sec', - cache.route({expire: 1}), - handle_timestamp -); - -app.all('/default_expire', - cache.route(), - handle_timestamp -); +app.all("/1sec", cache.route({ expire: 1 }), handle_timestamp); -app.all('/never_expire', - cache.route({expire: -1}), - handle_timestamp -); +app.all("/default_expire", cache.route(), handle_timestamp); -app.all('/delete_never_expire', - function(req, res) { - cache.del("/never_expire", function(err, count){ - if (err) { - return res.send(500); - } - return res.send("count:" + count); - }); +app.all("/never_expire", cache.route({ expire: -1 }), handle_timestamp); +app.all("/delete_never_expire", (req, res) => { + cache.del("/never_expire", (err, count) => { + if (err) { + return res.send(500); } -); -app.all('/', + return res.send(`count:${count}`); + }); +}); +app.all( + "/", cache.route(), - function (req, res) { - res.send('Now is ' + new Date()); - }); + (req, res) => { + res.send(`Now is ${new Date()}`); + } +); /* ======== server ======== */ -var server = require('http').createServer(app); +let server = require("http").createServer(app); -server.listen(app.get('port'), function () { - console.log('express-redis-cache test server started on port ' + app.get('port')); +server.listen(app.get("port"), () => { + console.log( + `express-redis-cache test server started on port ${app.get("port")}` + ); }); -server.on('error', function (error) { - console.log({ 'server error': error }); +server.on("error", error => { + console.log({ "server error": error }); }); diff --git a/index.js b/index.js deleted file mode 100644 index 06534c6..0000000 --- a/index.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * < M A I N > - * - * npm main - */ - -! function () { - - 'use strict'; - - module.exports = require('./lib/ExpressRedisCache').init; - -}(); diff --git a/jsdoc.json b/jsdoc.json new file mode 100644 index 0000000..ef5aa09 --- /dev/null +++ b/jsdoc.json @@ -0,0 +1,27 @@ +{ + "tags": { + "allowUnknownTags": true, + "dictionaries": ["jsdoc"] + }, + "source": { + "include": ["lib", "package.json", "README.md"], + "includePattern": ".js$", + "excludePattern": "(node_modules/|docs)" + }, + "plugins": [ + "plugins/markdown" + ], + "templates": { + "cleverLinks": false, + "monospaceLinks": true, + "useLongnameInNav": false, + "showInheritedInNav": true + }, + "opts": { + "destination": "./docs/", + "encoding": "utf8", + "private": true, + "recurse": true, + "template": "./node_modules/minami" + } +} \ No newline at end of file diff --git a/lib/ExpressRedisCache.js b/lib/ExpressRedisCache.js deleted file mode 100644 index 9cb05aa..0000000 --- a/lib/ExpressRedisCache.js +++ /dev/null @@ -1,170 +0,0 @@ -module.exports = (function () { - - 'use strict'; - - var config = require('../package.json').config; - - /** ExpressRedisCache - * - * @class - * @description Main class - * @extends EventEmitter - * @arg {Object} options? - Options (view README) - */ - - function ExpressRedisCache (options) { - - /** The request options - * - * @type Object - */ - - this.options = options || {}; - - /** The entry name prefix - * - * @type String - */ - - this.prefix = this.options.prefix || config.prefix; - - /** The host to connect to (default host if null) - * - * @type String - */ - - this.host = this.options.host || "localhost"; - - /** The port to connect to (default port if null) - * - * @type Number - */ - - this.port = this.options.port || "6379"; - - /** The password of Redis server (optional) - * - * @type String - */ - this.auth_pass = this.options.auth_pass; - - /** An alias to disable expiration for a specific route - * - * var cache = new ExpressRedisCache(); - * cache.route('page', cache.FOREVER); // cache will not expire - * - * @type number - */ - - this.FOREVER = -1; - - /** Set expiration time in seconds, default is -1 (No expire) - * @type number - */ - - this.expire = this.options.expire || this.FOREVER; - - /** Whether or not express-redis-cache is connected to Redis - * - * @type Boolean - */ - - this.connected = false; - - /** The Redis Client - * - * @type Object (preferably a client from the official Redis module) - */ - - this.client = this.options.client || require('redis').createClient(this.port, this.host, { auth_pass: this.auth_pass }); - - /** If client can emit */ - - if ( this.client.on ) { - this.client.on('error', function (error) { - this.emit('error', error); - }.bind(this)); - - this.client.on('connect', function () { - this.connected = true; - this.emit('connected', { host: this.host, port: this.port }); - this.emit('message', 'OK connected to redis://' + this.client.address); - }.bind(this)); - - this.client.on('end', function () { - this.connected = false; - this.emit('disconnected', { host: this.host, port: this.port }); - this.emit('message', 'Disconnected from redis://' + this.client.host + ':' + this.client.port); - }.bind(this)); - } - } - - /** Extend Event Emitter */ - - require('util').inherits(ExpressRedisCache, require('events').EventEmitter); - - /** js-comment - * - * @method - * @description Get - - * @return void{Object} - * @arg {Object} arg - About arg - */ - - ExpressRedisCache.prototype.get = require('./ExpressRedisCache/get'); - - /** js-comment - * - * @method - * @description This is a method - * @return void{Object} - * @arg {Object} arg - About arg - */ - - ExpressRedisCache.prototype.add = require('./ExpressRedisCache/add'); - - /** js-comment - * - * @method - * @description This is a method - * @return void{Object} - * @arg {Object} arg - About arg - */ - - ExpressRedisCache.prototype.del = require('./ExpressRedisCache/del'); - - /** js-comment - * - * @method - * @description This is a method - * @return void{Object} - * @arg {Object} arg - About arg - */ - - ExpressRedisCache.prototype.route = require('./ExpressRedisCache/route'); - - /** js-comment - * - * @method - * @description This is a method - * @return void{Object} - * @arg {Object} arg - About arg - */ - - ExpressRedisCache.prototype.size = require('./ExpressRedisCache/size'); - - /** js-comment - * - * @function - * @description Factory for ExpressRedisCache - * @return ExpressRedisCache - * @arg {Object} arg - About arg - */ - - ExpressRedisCache.init = function (options) { - return new ExpressRedisCache(options); - }; - - return ExpressRedisCache; - -})(); diff --git a/lib/ExpressRedisCache/add.js b/lib/ExpressRedisCache/add.js index d624009..374605c 100644 --- a/lib/ExpressRedisCache/add.js +++ b/lib/ExpressRedisCache/add.js @@ -1,80 +1,78 @@ -module.exports = (function () { +import util from "util"; +import { config } from "../../package.json"; +import sizeOf from "../sizeof"; - 'use strict'; +/** Add + * + * @function + * @description Add a new cache entry + * @return void + * @callback + * @arg {String} name - The cache entry name + * @arg {String} body - The cache entry body + * @arg {Object} options - Optional { type: String, expire: Number } + * @arg {Number} expire - The cache life time in seconds [OPTIONAL] + * @arg {Function} callback + */ - var config = require('../../package.json').config; +function add(name, body, options, callback) { + let self = this; - /** Add - * - * @function - * @description Add a new cache entry - * @return void - * @callback - * @arg {String} name - The cache entry name - * @arg {String} body - The cache entry body - * @arg {Object} options - Optional { type: String, expire: Number } - * @arg {Number} expire - The cache life time in seconds [OPTIONAL] - * @arg {Function} callback - */ - - function add (name, body, options, callback) { - var self = this; - - /** Adjust arguments in case @options is omitted **/ - if ( ! callback && (typeof options === 'function') ) { - callback = options; - options = {}; - } - - var domain = require('domain').create(); - - domain.on('error', domain.bind(function (error) { - self.emit('error', error); - self.connected = false; - callback(error); - })); + /** Adjust arguments in case @options is omitted **/ + if (!callback && typeof options === "function") { + callback = options; + options = {}; + } - domain.run(function () { + if (self.connected === false) { + return callback(null, []); // simulate cache miss + } - if (self.connected === false) { - return callback(null, []); // simulate cache miss - } + /** The new cache entry **/ + let entry = { + body: body, + type: options.type || config.type, + touched: +new Date(), + expire: + typeof options.expire !== "undefined" && options.expire !== false + ? options.expire + : self.expire + }; - /** The new cache entry **/ - var entry = { - body: body, - type: options.type || config.type, - touched: +new Date(), - expire: (typeof options.expire !== 'undefined' && options.expire !== false) ? options.expire : self.expire - }; + let size = sizeOf(entry); - var size = require('../sizeof')(entry); + let prefix = self.prefix.match(/:$/) + ? self.prefix.replace(/:$/, "") + : self.prefix; - var prefix = self.prefix.match(/:$/) ? self.prefix.replace(/:$/, '') - : self.prefix; + /* Save as a Redis hash */ + let redisKey = `${prefix}:${name}`; + self.client.hmset(redisKey, entry, (err, res) => { + let calculated_size = (size / 1024).toFixed(2); + /** If @expire then tell Redis to expire **/ + if (typeof entry.expire === "number" && entry.expire > 0) { + self.client.expire(redisKey, +entry.expire, () => { + const message = util.format( + "SET %s ~%d Kb %d TTL (sec)", + redisKey, + calculated_size, + +entry.expire + ); + self.emit("message", message); - /* Save as a Redis hash */ - var redisKey = prefix + ':' + name; - self.client.hmset(redisKey, entry, - domain.intercept(function (res) { - var calculated_size = (size / 1024).toFixed(2); - /** If @expire then tell Redis to expire **/ - if ( typeof entry.expire === 'number' && entry.expire > 0 ) { - self.client.expire(redisKey, +entry.expire, - domain.intercept(function () { - self.emit('message', require('util').format('SET %s ~%d Kb %d TTL (sec)', redisKey, calculated_size, +entry.expire)); - callback(null, name, entry, res); - })); - } - else - { - self.emit('message', require('util').format('SET %s ~%d Kb', redisKey, calculated_size)); - callback(null, name, entry, res); - } - })); - }); - } - - return add; + if (options.tag) { + self.emit("message", `SADD ${prefix}:${options.tag} "${redisKey}"`); + } + callback(null, name, entry, res); + }); + } else { + self.emit( + "message", + util.format("SET %s ~%d Kb", redisKey, calculated_size) + ); + callback(null, name, entry, res); + } + }); +} -})(); +export default add; diff --git a/lib/ExpressRedisCache/del.js b/lib/ExpressRedisCache/del.js index 7a5d913..37115f2 100644 --- a/lib/ExpressRedisCache/del.js +++ b/lib/ExpressRedisCache/del.js @@ -1,92 +1,79 @@ -module.exports = (function () { - - 'use strict'; - - /** Delete cache entries - * - * @method ExpressRedisCache.del - * @description Delete entry by name - * @return null - * @arg {String} name - The entry name - * @arg {Function} callback - */ - - function del (name, callback) { - var self = this; - - if ( typeof name !== 'string' ) { - return this.emit('error', new Error('ExpressRedisCache.del: missing first argument String')); - } - - if ( typeof callback !== 'function' ) { - return this.emit('error', new Error('ExpressRedisCache.del: missing second argument Function')); - } - - var domain = require('domain').create(); - - domain.on('error', function onDelError (error) { - callback(error); - }); - - domain.run(function delRun () { - - /** Get prefix */ - - var prefix = self.prefix.match(/:$/) ? self.prefix.replace(/:$/, '') - : self.prefix; - - /** Tell Redis to delete hash */ - - var redisKey = prefix + ':' + name; - - /** Detect wilcard syntax */ - - var hasWildcard = redisKey.indexOf('*') >= 0; - - /** If has wildcard */ +import util from "util"; +import async from "async"; + +/** Delete cache entries + * + * @method ExpressRedisCache.del + * @description Delete entry by name + * @return null + * @arg {String} name - The entry name + * @arg {Function} callback + */ + +function del(name, callback) { + let self = this; + + if (typeof name !== "string") { + return this.emit( + "error", + new Error("ExpressRedisCache.del: missing first argument String") + ); + } - if ( hasWildcard ) { + if (typeof callback !== "function") { + return this.emit( + "error", + new Error("ExpressRedisCache.del: missing second argument Function") + ); + } - /** Get a list of keys using the wildcard */ + /** Get prefix */ - self.client.keys(redisKey, domain.intercept(function onKeys (keys) { + let prefix = self.prefix.match(/:$/) + ? self.prefix.replace(/:$/, "") + : self.prefix; - require('async').each(keys, + /** Tell Redis to delete hash */ - function onEachKey (key, callback) { - self.client.del(key, domain.intercept(function () { - self.emit('message', require('util').format('DEL %s', key)); - callback(); - })); - }, + let redisKey = `${prefix}:${name}`; - function onEachKeyDone (error) { + /** Detect wilcard syntax */ - if ( error ) { - throw error; - } + let hasWildcard = redisKey.indexOf("*") >= 0; - callback(null, keys.length); + /** If has wildcard */ - }); + if (hasWildcard) { + /** Get a list of keys using the wildcard */ - })); + self.client.keys(redisKey, (err, keys) => { + async.each( + keys, - } + (key, callback) => { + self.client.del(key, () => { + self.emit("message", util.format("DEL %s", key)); + callback(); + }); + }, - /** No wildcard **/ + error => { + if (error) { + throw error; + } - else { - self.client.del(redisKey, - domain.intercept(function onKeyDeleted (deletions) { - self.emit('message', require('util').format('DEL %s', redisKey)); - callback(null, +deletions); - })); - } + callback(null, keys.length); + } + ); + }); + } else { + /** No wildcard **/ + self.client.del(redisKey, (err, deletions) => { + self.emit("message", util.format("DEL %s", redisKey)); + callback(null, +deletions); }); } +} - return del; - -})(); \ No newline at end of file +export default del; diff --git a/lib/ExpressRedisCache/delTag.js b/lib/ExpressRedisCache/delTag.js new file mode 100644 index 0000000..b240397 --- /dev/null +++ b/lib/ExpressRedisCache/delTag.js @@ -0,0 +1,63 @@ +import util from "util"; +import async from "async"; + +/** Delete cache entries by tag + * + * @method ExpressRedisCache.delTag + * @description Delete entries by tag + * @return null + * @arg {String} name - The tag name + * @arg {Function} callback + */ + +function delTag(name, callback) { + let self = this; + + if (typeof name !== "string") { + return this.emit( + "error", + new Error("ExpressRedisCache.delTag: missing first argument String") + ); + } + + if (typeof callback !== "function") { + return this.emit( + "error", + new Error("ExpressRedisCache.delTag: missing second argument Function") + ); + } + + /** Get prefix */ + + let prefix = self.prefix.match(/:$/) + ? self.prefix.replace(/:$/, "") + : self.prefix; + + /** Tell Redis to delete hash */ + + let redisKey = `${prefix}:${name}`; + + self.client.smembers(redisKey, (err, deletions) => { + deletions.push(redisKey); + async.each( + deletions, + + (key, callback) => { + self.client.del(key, () => { + self.emit("message", util.format("DEL %s", key)); + callback(); + }); + }, + + error => { + if (error) { + throw error; + } + + callback(null, deletions.length); + } + ); + }); +} + +export default delTag; diff --git a/lib/ExpressRedisCache/expire.js b/lib/ExpressRedisCache/expire.js index 3ac947d..f472e24 100644 --- a/lib/ExpressRedisCache/expire.js +++ b/lib/ExpressRedisCache/expire.js @@ -1,69 +1,68 @@ -module.exports = (function () { +// Convert HTTP status codes into 1xx, 2xx, 3xx, 4xx, 5xx +function maskStatus(statusCode) { + return `${String(statusCode).match(/(\d)\d\d/)[1]}xx`; +} - 'use strict'; - - // Convert HTTP status codes into 1xx, 2xx, 3xx, 4xx, 5xx - function maskStatus (statusCode) { - return String(statusCode).match(/(\d)\d\d/)[1] + 'xx'; +// Turn the policy argument into a function that consumes a +// status code and returns the expiration value +function createExpirationPolicy(options) { + if ( + typeof options !== "object" && + typeof options !== "number" && + typeof options !== "function" + ) { + throw new Error(`expire option cannot be type ${typeof options}`); } - // Turn the policy argument into a function that consumes a - // status code and returns the expiration value - function createExpirationPolicy (options) { - if (typeof options !== 'object' && typeof options !== 'number' && typeof options !== 'function') { - throw new Error('expire option cannot be type ' + typeof options); - } + // If what's passed in is a function, return the function. + if (typeof options === "function") { + return options; + } - // If what's passed in is a function, return the function. - if ( typeof options === 'function' ) { - return options; - } + // Internally store expiration as an object, + // so if a number is provided, use that as the default + if (typeof options === "number") { + options = { + xxx: options + }; + } - // Internally store expiration as an object, - // so if a number is provided, use that as the default - if ( typeof options === 'number' ) { - options = { - 'xxx': options - }; + for (let k in options) { + // Ensure that keys are in the form xxx, 4xx, or 400 + if (!k.match(/xxx/i) && !k.match(/[1-5]xx/i) && !k.match(/[1-5][0-9]{2}/)) { + throw new Error(`invalid statusCode ${k}`); } - - for (var k in options) { - // Ensure that keys are in the form xxx, 4xx, or 400 - if (!k.match(/xxx/i) && !k.match(/[1-5]xx/i) && !k.match(/[1-5][0-9]{2}/)) { - throw new Error('invalid statusCode ' + k); - } - // Ensure that the expiration values are numbers - if (typeof options[k] !== 'number') { - throw new Error('invalid expiration for statusCode ' + k); - } - // Convert keys to lower case - var v = options[k]; - delete options[v]; - options[k.toLowerCase()] = v; + // Ensure that the expiration values are numbers + if (typeof options[k] !== "number") { + throw new Error(`invalid expiration for statusCode ${k}`); } + // Convert keys to lower case + let v = options[k]; + delete options[v]; + options[k.toLowerCase()] = v; + } - // Ensure that there is a default so we can always return a value - if (!options.hasOwnProperty('xxx')) { - throw new Error('no default expiration provided'); - } + // Ensure that there is a default so we can always return a value + if (!options.hasOwnProperty("xxx")) { + throw new Error("no default expiration provided"); + } - return function (req, res) { - var statusCode = res.statusCode; + return function(req, res) { + let statusCode = res.statusCode; - // Look for exact status code matches first - if (options.hasOwnProperty(statusCode)) { - return options[statusCode]; - } - // Test for a 4xx style match - else if (options.hasOwnProperty(maskStatus(statusCode))) { - return options[maskStatus(statusCode)]; - } - // Fallback to the default expiration value - else { - return options.xxx; - } - }; - } + // Look for exact status code matches first + if (options.hasOwnProperty(statusCode)) { + return options[statusCode]; + } + // Test for a 4xx style match + else if (options.hasOwnProperty(maskStatus(statusCode))) { + return options[maskStatus(statusCode)]; + } + // Fallback to the default expiration value + else { + return options.xxx; + } + }; +} - return createExpirationPolicy; -})(); +export default createExpirationPolicy; diff --git a/lib/ExpressRedisCache/get.js b/lib/ExpressRedisCache/get.js index dac1ffa..7645bdf 100644 --- a/lib/ExpressRedisCache/get.js +++ b/lib/ExpressRedisCache/get.js @@ -1,92 +1,81 @@ -module.exports = (function () { - - 'use strict'; - - /** Get - * - * @function - * @description - * @return void - * @callback - * @arg {String} name - The cache entry name to get (wildcards accepted) - * @arg {Function} callback - Callback - */ - - function get (name, callback) { - var self = this; - - var domain = require('domain').create(); +import async from "async"; +import util from "util"; +import sizeOf from "../sizeof"; + +/** Get + * + * @function + * @return void + * @callback + * @arg {String} name - The cache entry name to get (wildcards accepted) + * @arg {Function} callback - Callback + */ + +function get(name, callback) { + let self = this; + + if (typeof name === "function") { + callback = name; + name = "*"; + } - domain.on('error', function (error) { - self.emit('error', error); - callback(error); - domain.exit(); + let prefix = self.prefix.match(/:$/) + ? self.prefix.replace(/:$/, "") + : self.prefix; + + let redisKey = `${prefix}:${name || "*"}`; + + /** Detect wildcard syntax */ + let hasWildcard = redisKey.indexOf("*") >= 0; + + let fetchKey = function(key, cb) { + self.client.hgetall(key, (err, result) => { + if (result) { + let names = key.split(":"); + result.name = names[1]; + result.prefix = names[0]; + self.emit( + "message", + util.format("GET %s ~%d Kb", key, (sizeOf(result) / 1024).toFixed(2)) + ); + } + cb(err, result); }); + }; - domain.run(function () { + /** If has wildcard */ + if (hasWildcard) { + /** Get a list of keys using the wildcard */ - if ( typeof name === 'function' ) { - callback = name; - name = '*'; + self.client.keys(`${prefix}:${name}`, (err, keys) => { + if (!keys.length) { + callback(null, []); + return; } - var prefix = self.prefix.match(/:$/) ? self.prefix.replace(/:$/, '') - : self.prefix; - - var redisKey = prefix + ':' + (name ||'*'); - - /** Detect wildcard syntax */ - var hasWildcard = redisKey.indexOf('*') >= 0; - - var fetchKey = function (key, cb) { - self.client.hgetall(key, domain.intercept(function (result) { - if ( result ) { - var names = key.split(':'); - result.name = names[1]; - result.prefix = names[0]; - self.emit('message', require('util').format('GET %s ~%d Kb', key, - (require('../sizeof')(result) / 1024).toFixed(2))); - } - cb(null, result); - })); - }; - - /** If has wildcard */ - if ( hasWildcard ) { - /** Get a list of keys using the wildcard */ - self.client.keys(prefix + ':' + name, domain.intercept(function (keys) { - if ( ! keys.length ) { - callback(null, []); - return domain.exit(); - } - - require('async').parallel(keys.map(function (key) { - return function (cb) { - return fetchKey(key, cb); - }; - }), domain.intercept(function (results) { - callback(null, results); - domain.exit(); - })); - })); - } - /** No wildcard **/ - else { - fetchKey(redisKey, domain.intercept(function (result) { - if( result ) { - callback(null, [ result ]); - domain.exit(); - } - else { - callback(null, []); - domain.exit(); - } - })); + async.parallel( + keys.map(key => { + return function(cb) { + return fetchKey(key, cb); + }; + }), + (err, results) => { + callback(null, results); + } + ); + }); + } else { + /** No wildcard **/ + + fetchKey(redisKey, (err, result) => { + if (result) { + callback(err, [result]); + } else { + callback(err, []); } }); } +} - return get; - -}) (); +export default get; diff --git a/lib/ExpressRedisCache/route.js b/lib/ExpressRedisCache/route.js index 6b46ea4..c4fdced 100644 --- a/lib/ExpressRedisCache/route.js +++ b/lib/ExpressRedisCache/route.js @@ -1,221 +1,218 @@ -module.exports = (function () { +import Expire from "./expire"; - 'use strict'; +/** route() - Create a middleware + * + * @method ExpressRedisCache.route + * @return {Function} middleware + */ - /** route() - Create a middleware +function route() { + /** A reference to this * - * @method ExpressRedisCache.route - * @return {Function} middleware + * @type ExpressRedisCache */ - function route () { + let self = this; - /** The middleware to return - * - * @type Function - */ + /** The route options + * + * @type List + */ - var middleware; + let options = arguments; - /** A reference to this - * - * @type ExpressRedisCache - */ + // Build the middleware function + + /** + * @function + * @arg {IncomingMessage} req + * @arg {HttpResponse} res + * @arg {Function} next + */ - var self = this; + return function expressRedisCache_Middleware(req, res, next) { + if (res.expressRedisCache) { + self.emit("deprecated", { + deprecated: "expressRedisCache", + substitute: "use_express_redis_cache", + file: __filename, // eslint-disable-line + line: __line // eslint-disable-line + }); - /** The route options - * - * @type List - */ + res.use_express_redis_cache = res.expressRedisCache; + } - var options = arguments; + // If cache is disabled, call next() + if (res.use_express_redis_cache === false) { + return next(); + } - /** The domain handler - * - * @type Domain - */ + // If the cache isn't connected, call next() - var domain = require('domain').create(); + if (self.connected === false || self.client.connected === false) { + return next(); + } - /** The domain error handler + /** Cache entry name * - * @type Domain + * @type String + * @description The name the cache entry will be saved under + * @default req.originalUrl */ - domain.on('error', function (error) { - self.emit('error', error); - }); - - domain.run(function () { - // Build the middleware function + let name = req.originalUrl; - /** - * @function - * @arg {IncomingMessage} req - * @arg {HttpResponse} res - * @arg {Function} next - */ - - middleware = function expressRedisCache_Middleware (req, res, next) { - - if ( res.expressRedisCache ) { - self.emit('deprecated', { - deprecated: 'expressRedisCache', - substitute: 'use_express_redis_cache', - file: __fileName, - line: __line - }); - - res.use_express_redis_cache = res.expressRedisCache; - - } - - // If cache is disabled, call next() - if ( res.use_express_redis_cache === false ) { - return next(); - } + /** + * @deprecated `res.expressRedisCacheName` is deprecated starting on v0.1.1, `use res.express_redis_cache_name` instead + */ - // If the cache isn't connected, call next() + if (res.expressRedisCacheName) { + self.emit("deprecated", { + deprecated: "expressRedisCacheName", + substitute: "express_redis_cache_name", + file: __filename, + line: __line // eslint-disable-line + }); - if ( self.connected === false || self.client.connected === false ) { - return next(); - } + res.express_redis_cache_name = res.expressRedisCacheName; + } - /** Cache entry name - * - * @type String - * @description The name the cache entry will be saved under - * @default req.originalUrl - */ + // If a cache has been explicitly attached to `res` then use it as name - var name = req.originalUrl; + if (res.express_redis_cache_name) { + name = res.express_redis_cache_name; + } - /** - * @deprecated `res.expressRedisCacheName` is deprecated starting on v0.1.1, `use res.express_redis_cache_name` instead - */ + // If a tag has been explicitly attached to `res` then use it as tag - if ( res.expressRedisCacheName ) { - self.emit('deprecated', { - deprecated: 'expressRedisCacheName', - substitute: 'express_redis_cache_name', - file: __fileName, - line: __line - }); + if (res.express_redis_cache_tag) { + tag = res.express_redis_cache_tag; + } - res.express_redis_cache_name = res.expressRedisCacheName; - } + // If route() was called with a string as its first argument, use this string as name - // If a cache has been explicitly attached to `res` then use it as name + if (typeof options[0] === "string") { + name = options[0]; + } - if ( res.express_redis_cache_name ) { - name = res.express_redis_cache_name; - } - - // If route() was called with a string as its first argument, use this string as name - - if ( typeof options[0] === 'string' ) { - name = options[0]; - } + if (typeof options[0] === "object" && typeof options[0].name === "string") { + name = options[0].name; + } - if ( typeof options[0] === 'object' && typeof options[0].name === 'string' ) { - name = options[0].name; - } + /** Name cannot have wildcards in them */ - /** Name cannot have wildcards in them */ + if (/\*/.test(name)) { + return next(new Error("Name can not have wildcards")); + } - if ( /\*/.test(name) ) { - return next(new Error('Name can not have wildcards')); - } + /** The seconds entry lives + * + * @type Number + * @default this.expire + */ - /** The seconds entry lives - * - * @type Number - * @default this.expire - */ - var expire = self.expire; - if ( typeof options[0] === 'object' ) { - if ( typeof options[0].expire === 'number' || typeof options[0].expire === 'object' || typeof options[0].expire === 'function') { - expire = options[0].expire; - } - } + let expire = self.expire; - if ( typeof options[0] === 'number' ) { - expire = options[0]; - } - else if ( typeof options[1] === 'number' || typeof options[1] === 'object') { - expire = options[1]; - } + /** The object representing the tag for the cache key + * + * @type String + * @default this.tag + */ - var binary = false; - if ( typeof options[0] === 'object' && typeof options[0].binary === 'boolean' ) { - binary = options[0].binary; + let tag = self.tag; + + if (typeof options[0] === "object") { + if ( + typeof options[0].expire === "number" || + typeof options[0].expire === "object" || + typeof options[0].expire === "function" + ) { + expire = options[0].expire; + } + + if (typeof options[0].tag === "string") { + tag = options[0].tag; + } + } + + if (typeof options[0] === "number") { + expire = options[0]; + } else if ( + typeof options[1] === "number" || + typeof options[1] === "object" + ) { + expire = options[1]; + } + + let binary = false; + if ( + typeof options[0] === "object" && + typeof options[0].binary === "boolean" + ) { + binary = options[0].binary; + } + + let expirationPolicy = Expire(expire); + + /** attempt to get cache **/ + self.get(name, (error, cache) => { + /** If there was an error with cache then call next **/ + + if (error) { + return next(); + } + + if (!res._headers["cache-control"] && typeof expire === "number") { + res._headers["cache-control"] = `max-age=${expire}000`; + } + + /** if it's cached, display cache **/ + + if (cache.length && cache[0].body != null) { + res.contentType(cache[0].type || "text/html"); + if (binary) { + //Convert back to binary buffer + res.send(new Buffer.from(cache[0].body).toString("base64")); + } else { + res.send(cache[0].body); } - - var expirationPolicy = require('./expire')(expire); - - /** attempt to get cache **/ - self.get(name, domain.bind(function (error, cache) { - - /** If there was an error with cache then call next **/ - - if ( error ) { - return next(); + } else { + /** otherwise, cache request **/ + /** wrap res.send **/ + let send = res.send.bind(res); + + res.send = function(body) { + /** send output to HTTP client **/ + let ret = send(body); + + /** convert binary to base64 string **/ + if (binary && typeof body !== "string") { + body = new Buffer.from(body).toString("base64"); } - /** if it's cached, display cache **/ - - if ( cache.length && cache[0].body != null ) { - res.contentType(cache[0].type || "text/html"); - if(binary){ //Convert back to binary buffer - res.send(new Buffer(cache[0].body, 'base64')); - }else{ - res.send(cache[0].body); - } - } - - /** otherwise, cache request **/ - else { - - /** wrap res.send **/ - var send = res.send.bind(res); - - res.send = function (body) { - - /** send output to HTTP client **/ - var ret = send(body); - - /** convert binary to base64 string **/ - if(binary && typeof body !== 'string'){ - body = new Buffer(body).toString('base64'); - } - - /** save only strings to cache **/ - if ( typeof body !== 'string' ) { - return ret; - } - - /** Create the new cache **/ - self.add(name, body, { - type: this._headers['content-type'], - expire: expirationPolicy(req, res) - }, - domain.intercept(function (name, cache) {})); - - return ret; - - }; - - return next(); + /** save only strings to cache **/ + if (typeof body !== "string") { + return ret; } - })); - }; + /** Create the new cache **/ + self.add( + name, + body, + { + type: this._headers["content-type"], + expire: expirationPolicy(req, res), + tag + }, + function (name, cache) {}); // eslint-disable-line + + return ret; + }; + + return next(); + } }); + }; +} - return middleware; - } - - return route; - -}) (); +export default route; diff --git a/lib/ExpressRedisCache/size.js b/lib/ExpressRedisCache/size.js index a1b9f1d..1d42f04 100644 --- a/lib/ExpressRedisCache/size.js +++ b/lib/ExpressRedisCache/size.js @@ -1,54 +1,32 @@ -/** +import async from "async"; +import sizeOf from "../sizeof"; - cache.ls() - ########## - - This script is supposed to be called via `index.js` - -**/ - -module.exports = function ( -/* Function */ callback // Callback +export default function( + /* Function */ callback // Callback ) { - /** set in /index.js **/ - var self = this; - - var domain = require('domain').create(); - - domain.on('error', function (error) { - callback(error); - }); - - domain.run(function () { - - /** Tell Redis to fetch the keys name beginning by prefix **/ - self.client.keys(self.prefix + '*', domain.intercept(function (keys) { - - var size = 0; - - require('async').parallel( - - /** for each keys **/ - - keys.map(function (key) { - return function (cb) { - - self.get(this.key.replace(new RegExp('^' + self.prefix), ''), cb); + let self = this; - } - .bind({ key: key }); - }), + /** Tell Redis to fetch the keys name beginning by prefix **/ + self.client.keys(`${self.prefix}*`, (err, keys) => { + let size = 0; - domain.intercept(function (results) { - results.forEach(function (result) { - size += require('../sizeof')(result); - }); + async.parallel( + /** for each keys **/ - callback(null, size); - })); + keys.map(key => { + return function(cb) { + self.get(this.key.replace(new RegExp(`^${self.prefix}`), ""), cb); + }.bind({ key: key }); + }), - })); + results => { + results.forEach(result => { + size += sizeOf(result); + }); + callback(null, size); + } + ); }); -}; \ No newline at end of file +} diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..7736977 --- /dev/null +++ b/lib/index.js @@ -0,0 +1,174 @@ +import { EventEmitter } from "events"; +import redis from "redis"; +import Get from "./ExpressRedisCache/get"; +import Add from "./ExpressRedisCache/add"; +import Del from "./ExpressRedisCache/del"; +import DelTag from "./ExpressRedisCache/delTag"; +import Route from "./ExpressRedisCache/route"; +import Size from "./ExpressRedisCache/size"; +import { config } from "../package.json"; + +/** ExpressRedisCache + * + * @class + * @description Main class + * @extends EventEmitter + * @arg {Object} options? - Options (view README) + */ + +export default class ExpressRedisCache extends EventEmitter { + constructor(options) { + super(options); + + /** The request options + * + * @type Object + */ + + this.options = options || {}; + + /** The entry name prefix + * + * @type String + */ + + this.prefix = this.options.prefix || config.prefix; + + /** The host to connect to (default host if null) + * + * @type String + */ + + this.host = this.options.host || "localhost"; + + /** The port to connect to (default port if null) + * + * @type Number + */ + + this.port = this.options.port || "6379"; + + /** The password of Redis server (optional) + * + * @type String + */ + this.auth_pass = this.options.auth_pass; + + /** An alias to disable expiration for a specific route + * + * var cache = new ExpressRedisCache(); + * cache.route('page', cache.FOREVER); // cache will not expire + * + * @type number + */ + + this.FOREVER = -1; + + /** Set expiration time in seconds, default is -1 (No expire) + * @type number + */ + + this.expire = this.options.expire || this.FOREVER; + + /** Whether or not express-redis-cache is connected to Redis + * + * @type Boolean + */ + + this.connected = false; + + /** The Redis Client + * + * @type Object + */ + + this.client = + this.options.client || + redis.createClient(this.port, this.host, { auth_pass: this.auth_pass }); + + /** If client can emit */ + + if (this.client.on) { + this.client.on("error", error => { + console.error(error); + this.connected = false; + this.emit("message", "Redis is unavailable or not running"); + }); + + this.client.on("connect", () => { + this.connected = true; + this.emit("connected", { host: this.host, port: this.port }); + this.emit("message", `OK connected to redis://${this.client.address}`); + }); + + this.client.on("end", () => { + this.connected = false; + this.emit("disconnected", { host: this.host, port: this.port }); + this.emit( + "message", + `Disconnected from redis://${this.client.host}:${this.client.port}` + ); + }); + } + + /** js-comment + * + * @method + * @description Get - + * @return void{Object} + * @arg {Object} arg - About arg + */ + + this.get = Get; + + /** js-comment + * + * @method + * @description This is a method + * @return void{Object} + * @arg {Object} arg - About arg + */ + + this.add = Add; + + /** js-comment + * + * @method + * @description This is a method + * @return void{Object} + * @arg {Object} arg - About arg + */ + + this.del = Del; + + /** js-comment + * + * @method + * @description This is a method + * @return void{Object} + * @arg {Object} arg - About arg + */ + + this.delTag = DelTag; + + /** js-comment + * + * @method + * @description This is a method + * @return void{Object} + * @arg {Object} arg - About arg + */ + + this.route = Route; + + /** js-comment + * + * @method + * @description This is a method + * @return void{Object} + * @arg {Object} arg - About arg + */ + + this.size = Size; + } +} diff --git a/lib/sizeof.js b/lib/sizeof.js index de3ebd3..75fb67a 100644 --- a/lib/sizeof.js +++ b/lib/sizeof.js @@ -16,43 +16,46 @@ http://creativecommons.org/publicdomain/zero/1.0/legalcode * * object - the object whose size should be determined */ -module.exports = function sizeof(object){ - +export default function sizeof(object) { // initialise the list of objects and size - var objects = [object]; - var size = 0; - var key; + let objects = [object]; + let size = 0; + let key; // loop over the objects - for (var index = 0; index < objects.length; index ++){ - + for (let index = 0; index < objects.length; index++) { // determine the type of the object - switch (typeof objects[index]){ - + switch (typeof objects[index]) { // the object is a boolean - case 'boolean': size += 4; break; + case "boolean": + size += 4; + break; // the object is a number - case 'number': size += 8; break; + case "number": + size += 8; + break; // the object is a string - case 'string': size += 2 * objects[index].length; break; + case "string": + size += 2 * objects[index].length; + break; // the object is a generic object - case 'object': - + case "object": // if the object is not an array, add the sizes of the keys - if (Object.prototype.toString.call(objects[index]) != '[object Array]'){ + if ( + Object.prototype.toString.call(objects[index]) != "[object Array]" + ) { for (key in objects[index]) size += 2 * key.length; } // loop over the keys - for (key in objects[index]){ - + for (key in objects[index]) { // determine whether the value has already been processed - var processed = false; - for (var search = 0; search < objects.length; search ++){ - if (objects[search] === objects[index][key]){ + let processed = false; + for (let search = 0; search < objects.length; search++) { + if (objects[search] === objects[index][key]) { processed = true; break; } @@ -60,14 +63,10 @@ module.exports = function sizeof(object){ // queue the value to be processed if appropriate if (!processed) objects.push(objects[index][key]); - } - } - } // return the calculated size return size; - -}; \ No newline at end of file +} diff --git a/package.json b/package.json index ae8fb9a..13a0949 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,17 @@ { "name": "express-redis-cache", - "version": "1.1.3", + "version": "2.0.0", "description": "A module to make Express interact with Redis (create, get, delete). You can automatically cache all your most popular routes in Redis.", "main": "index.js", "bin": { "express-redis-cache": "bin/express-redis-cache.js" }, "scripts": { - "test": "mocha --exit --check-leaks -R nyan test" + "prepare": "npm run build", + "build": "babel lib -d dist", + "test": "npm run build && mocha --exit --compilers js:@babel/register -R nyan test", + "debug": "npm run build && mocha --inspect-brk --exit --compilers js:@babel/register -R nyan test", + "docs": "jsdoc -c jsdoc.json" }, "repository": { "type": "git", @@ -53,13 +57,17 @@ { "name": "dam1", "url": "https://github.com/dam1" + }, + { + "name": "krazyjakee", + "url": "https://github.com/krazyjakee" } ], "license": "MIT", "dependencies": { "async": "^2.6.1", - "colors": "^1.3.0", - "redis": "^2.4.2" + "colors": "^1.3.1", + "redis": "^2.8.0" }, "directories": { "test": "test" @@ -69,12 +77,21 @@ "type": "text/html" }, "devDependencies": { + "@babel/cli": "^7.0.0-beta.56", + "@babel/core": "^7.0.0-beta.56", + "@babel/preset-env": "^7.0.0-beta.56", + "@babel/register": "^7.0.0-beta.56", "body-parser": "^1.18.3", + "eslint": "^5.3.0", + "eslint-config-prettier": "^2.9.0", + "eslint-plugin-prettier": "^2.6.2", "express": "^4.16.3", - "method-override": "^2.3.10", + "jsdoc": "^3.5.5", + "minami": "^1.2.3", "mocha": "^5.2.0", "moment": "^2.22.2", + "prettier": "1.14.0", "request": "^2.87.0", - "should": "^13.2.1" + "should": "^13.2.3" } } diff --git a/test/ExpressRedisCache.js b/test/ExpressRedisCache.js index 14670c2..1a4196c 100644 --- a/test/ExpressRedisCache.js +++ b/test/ExpressRedisCache.js @@ -1,77 +1,62 @@ -(function () { +import ERC from "../dist"; - 'use strict'; +let cache; +let prefix = process.env.EX_RE_CA_PREFIX || "erct:"; +let host = process.env.EX_RE_CA_HOST || "localhost"; +let port = process.env.EX_RE_CA_PORT || 6379; - var path = require('path'); - var assert = require('assert'); - - var mocha = require('mocha'); - var should = require('should'); - - var cache; - - var prefix = process.env.EX_RE_CA_PREFIX || 'erct:'; - var host = process.env.EX_RE_CA_HOST || 'localhost'; - var port = process.env.EX_RE_CA_PORT || 6379; - - describe ( 'Module', function () { - - it ( 'should be a function', function () { - cache = require('../'); - cache.should.be.a.function; - }); - - it ( 'should return a new ExpressRedisCache', function (done) { - cache = cache({ prefix: prefix, host: host, port: port }); - cache.constructor.name.should.equal('ExpressRedisCache'); - cache.on('error', function (error) { - throw error; - }); - cache.on('connected', function () { - done(); - }); - }); +describe("Module", () => { + it("should be a function", () => { + ERC.should.be.a.function; + }); - it ( 'should have a property options which is an object', function () { - cache.should.have.property('options') - .which.is.an.Object(); + it("should return a new ExpressRedisCache", done => { + cache = new ERC({ prefix: prefix, host: host, port: port }); + cache.constructor.name.should.equal("ExpressRedisCache"); + cache.on("error", error => { + throw error; }); - - it ( 'should have a property prefix which is a string and equals request prefix', function () { - cache.should.have.property('prefix').which.is.a.String(); - cache.prefix.should.equal(prefix); + cache.on("connected", () => { + done(); }); + }); - it ( 'should have a property host which is a string and equals request host', function () { - cache.should.have.property('host').which.is.a.String(); - cache.host.should.equal(host); - }); + it("should have a property options which is an object", () => { + cache.should.have.property("options").which.is.an.Object(); + }); - it ( 'should have a property port which is a number and equals request port', function () { - cache.should.have.property('port').which.is.a.Number(); - cache.port.should.equal(port); - }); + it("should have a property prefix which is a string and equals request prefix", () => { + cache.should.have.property("prefix").which.is.a.String(); + cache.prefix.should.equal(prefix); + }); - it ( 'should have a property FOREVER which is a number and equals -1', function () { - cache.should.have.property('FOREVER').which.is.a.Number(); - cache.FOREVER.should.equal(-1); - }); + it("should have a property host which is a string and equals request host", () => { + cache.should.have.property("host").which.is.a.String(); + cache.host.should.equal(host); + }); - it ( 'should have a property connected which is a boolean and is true', function () { - cache.should.have.property('connected').which.is.a.Boolean(); - cache.connected.should.be.true; - }); + it("should have a property port which is a number and equals request port", () => { + cache.should.have.property("port").which.is.a.Number(); + cache.port.should.equal(port); + }); - it ( 'should have a property expire which is a number and equals FOREVER', function () { - cache.should.have.property('expire').which.is.a.Number(); - cache.expire.should.equal(cache.FOREVER); - }); + it("should have a property FOREVER which is a number and equals -1", () => { + cache.should.have.property("FOREVER").which.is.a.Number(); + cache.FOREVER.should.equal(-1); + }); - it ( 'should have a property client which is a RedisClient', function () { - cache.should.have.property('client').which.is.an.Object(); - cache.client.constructor.name.should.equal('RedisClient'); - }); + it("should have a property connected which is a boolean and is true", () => { + cache.should.have.property("connected").which.is.a.Boolean(); + cache.connected.should.be.true; + }); + it("should have a property expire which is a number and equals FOREVER", () => { + cache.should.have.property("expire").which.is.a.Number(); + cache.expire.should.equal(cache.FOREVER); }); -})(); \ No newline at end of file + it("should have a property client which is a RedisClient", () => { + cache.should.have.property("client").which.is.an.Object(); + cache.client.constructor.name.should.equal("RedisClient"); + }); +}); diff --git a/test/add.js b/test/add.js index 9844e1d..c027636 100644 --- a/test/add.js +++ b/test/add.js @@ -1,119 +1,103 @@ -(function () { +import should from "should"; +import { config } from "../package.json"; +import ERC from "../dist"; - 'use strict'; +let prefix = process.env.EX_RE_CA_PREFIX || "erct:"; +let host = process.env.EX_RE_CA_HOST || "localhost"; +let port = process.env.EX_RE_CA_PORT || 6379; - var path = require('path'); - var assert = require('assert'); +let _name = "test1"; +let _body = "test1 test1 test1"; - var mocha = require('mocha'); - var should = require('should'); +const cache = new ERC({ + prefix, + host, + port, + expire: 2 +}); - var config = require('../package.json').config; +describe("add", () => { + let error, name, entry; - var prefix = process.env.EX_RE_CA_PREFIX || 'erct:'; - var host = process.env.EX_RE_CA_HOST || 'localhost'; - var port = process.env.EX_RE_CA_PORT || 6379; - - var _name = 'test1'; - var _body = 'test1 test1 test1'; - var _type = 'text/plain'; - - var cache = require('../')({ - prefix: prefix, - host: host, - port: port, - expire: 2 + it("should be a function", () => { + cache.add.should.be.a.Function(); }); - describe ( 'add', function () { - - var error, name, entry; - - it ( 'should be a function', function () { - cache.add.should.be.a.Function(); - }); - - it ( 'should callback', function (done) { - cache.add(_name, _body, - function ($error, $name, $entry) { - error = $error; - name = $name; - entry = $entry; - done(); - }); + it("should callback", done => { + cache.add(_name, _body, ($error, $name, $entry) => { + error = $error; + name = $name; + entry = $entry; + done(); }); + }); - it ( 'should allow for zero expiration', function(done) { - cache.add(_name, _body, { expire: 0 }, - function($error, $name, $entry) { - var resp; - if($entry.expire !== 0) { - var resp = new Error('entry.expire should be 0. It is '+$entry.expire); - } - done(resp); - } - ); + it("should allow for zero expiration", done => { + cache.add(_name, _body, { expire: 0 }, (err, $name, $entry) => { + let resp; + if ($entry.expire !== 0) { + resp = new Error(`entry.expire should be 0. It is ${$entry.expire}`); + } + done(resp); }); + }); - it ( 'should not have error', function () { - should(error).be.null; - }); + it("should not have error", () => { + should(error).be.null; + }); - it ( 'should have a name which is a string and match the request', function () { - name.should.be.a.String(); - name.should.equal(_name); - }); + it("should have a name which is a string and match the request", () => { + name.should.be.a.String(); + name.should.equal(_name); + }); - it ( 'should have a entry which is an object', function () { - entry.should.be.an.Object(); - }); + it("should have a entry which is an object", () => { + entry.should.be.an.Object(); + }); - it ( ' - entry which has a property body which a string matching the request', function () { - entry.body.should.be.a.String(); - entry.body.should.equal(_body); - }); + it(" - entry which has a property body which a string matching the request", () => { + entry.body.should.be.a.String(); + entry.body.should.equal(_body); + }); - it ( ' - entry which has a property type which a string matching default type', function () { - entry.type.should.be.a.String(); - entry.type.should.equal(config.type); - }); + it(" - entry which has a property type which a string matching default type", () => { + entry.type.should.be.a.String(); + entry.type.should.equal(config.type); + }); - it ( ' - entry which has a property touched which is a number which, when resolved to date, is less than 2 seconds from now', function () { - entry.touched.should.be.a.Number(); + it(" - entry which has a property touched which is a number which, when resolved to date, is less than 2 seconds from now", () => { + entry.touched.should.be.a.Number(); - var date = new Date(entry.touched); + let date = new Date(entry.touched); - ( (Date.now() - date) ).should.be.below(2000); - }); + (Date.now() - date).should.be.below(2000); + }); - it ( ' - entry which has a property expire which equals cache.expire', function () { - should(entry.expire).equal(cache.expire); - }); + it(" - entry which has a property expire which equals cache.expire", () => { + should(entry.expire).equal(cache.expire); + }); - it ( 'should have cached the content', function (done) { - this.timeout(2500); // allow more time for this test - - setTimeout(function(){ - cache.get(_name, function (err, res) { - should(err).not.be.ok; - res.should.be.an.Array(); - res.should.have.a.lengthOf(1); - done(); - }); - }, (cache.expire - 1) * 1000); + it("should have cached the content", done => { + cache.add(_name, _body, { expire: -1 }, () => { + cache.get(_name, (err, res) => { + should(err).not.be.ok; + res.should.be.an.Array(); + res.should.have.a.lengthOf(1); + done(); + }); }); + }); - it ( 'should expire in ' + cache.expire + ' seconds', function (done) { - this.timeout(2500); // allow more time for this test - - setTimeout(function(){ - cache.get(_name, function (err, res) { - should(err).not.be.ok; - res.should.be.an.Array(); - res.should.have.a.lengthOf(0); - done(); - }); - }, cache.expire * 1000); - }); + it(`should expire in ${cache.expire} seconds`, function(done) { + this.timeout(2500); // allow more time for this test + + setTimeout(() => { + cache.get(_name, (err, res) => { + should(err).not.be.ok; + res.should.be.an.Array(); + res.should.have.a.lengthOf(0); + done(); + }); + }, cache.expire * 1000); }); -})(); +}); diff --git a/test/del.js b/test/del.js index 7a92a3e..92923eb 100644 --- a/test/del.js +++ b/test/del.js @@ -1,99 +1,85 @@ -(function () { - 'use strict'; +import should from "should"; +import async from "async"; +import ERC from "../dist"; - var path = require('path'); - var assert = require('assert'); +let prefix = process.env.EX_RE_CA_PREFIX || "erct:"; +let host = process.env.EX_RE_CA_HOST || "localhost"; +let port = process.env.EX_RE_CA_PORT || 6379; - var mocha = require('mocha'); - var should = require('should'); +const cache = new ERC({ + prefix: prefix, + host: host, + port: port +}); - var prefix = process.env.EX_RE_CA_PREFIX || 'erct:'; - var host = process.env.EX_RE_CA_HOST || 'localhost'; - var port = process.env.EX_RE_CA_PORT || 6379; +describe("del", () => { + let error, deletions; - var cache = require('../')({ - prefix: prefix, - host: host, - port: port + before(done => { + cache.add("test-to-del", "-", done); }); - describe ( 'del', function () { - - var error, deletions; - - before(function (done) { - cache.add('test-to-del', '-', done); - }); - - it ( 'should be a function', function () { - cache.del.should.be.a.Function; - }); - - it ( 'should callback', function (done) { - cache.del('test-to-del', function ($error, $deletions) { - error = $error; - deletions = $deletions; - done(); - }); - }); - - it ( 'should not have error', function () { - should(error).be.null; - }); - - it ( 'should be a number', function () { - deletions.should.be.a.Number; - }); + it("should be a function", () => { + cache.del.should.be.a.Function; + }); - it ( 'should be a 1 or above', function () { - deletions.should.be.above(0); + it("should callback", done => { + cache.del("test-to-del", ($error, $deletions) => { + error = $error; + deletions = $deletions; + done(); }); - }); - describe ( 'del with wilcard', function () { - - var error, deletions; - - before(function (done) { - - var parallel = [0, 1, 2, 3 ,4, 5].map(function (num) { + it("should not have error", () => { + should(error).be.null; + }); - return function (done) { - cache.add('test-to-del.' + this.num, '-', done); - }.bind({ num: num }); + it("should be a number", () => { + deletions.should.be.a.Number; + }); - }); + it("should be a 1 or above", () => { + deletions.should.be.above(0); + }); +}); - require('async').series(parallel, function (error) { - done(error); - }); - }); +describe("del with wilcard", () => { + let error, deletions; - it ( 'should be a function', function () { - cache.del.should.be.a.Function; + before(done => { + let parallel = [0, 1, 2, 3, 4, 5].map(num => { + return function(done) { + cache.add(`test-to-del.${this.num}`, "-", done); + }.bind({ num: num }); }); - it ( 'should callback', function (done) { - cache.del('test-to-del.*', function ($error, $deletions) { - error = $error; - deletions = $deletions; - done(); - }); + async.series(parallel, error => { + done(error); }); + }); - it ( 'should not have error', function () { - should(error).be.null; - }); + it("should be a function", () => { + cache.del.should.be.a.Function; + }); - it ( 'should be a number', function () { - deletions.should.be.a.Number; + it("should callback", done => { + cache.del("test-to-del.*", ($error, $deletions) => { + error = $error; + deletions = $deletions; + done(); }); + }); - it ( 'should be a 1 or above', function () { - deletions.should.be.eql(6); - }); + it("should not have error", () => { + should(error).be.null; + }); + it("should be a number", () => { + deletions.should.be.a.Number; }); -})(); \ No newline at end of file + it("should be a 1 or above", () => { + deletions.should.be.eql(6); + }); +}); diff --git a/test/delTag.js b/test/delTag.js new file mode 100644 index 0000000..312b36c --- /dev/null +++ b/test/delTag.js @@ -0,0 +1,37 @@ +import should from "should"; +import async from "async"; +import ERC from "../dist"; + +let prefix = process.env.EX_RE_CA_PREFIX || "erct:"; +let host = process.env.EX_RE_CA_HOST || "localhost"; +let port = process.env.EX_RE_CA_PORT || 6379; + +const cache = new ERC({ + prefix: prefix, + host: host, + port: port +}); + +describe("delTag", () => { + before(done => { + cache.add( + "tag-to-del", + "-", + { + tag: "testtag" + }, + done + ); + }); + + it("should be a function", () => { + cache.delTag.should.be.a.Function; + }); + + it("should callback", done => { + cache.delTag("testtag", ($error, $deletions) => { + debugger; + done(); + }); + }); +}); diff --git a/test/expire.js b/test/expire.js index 009a19a..095e273 100644 --- a/test/expire.js +++ b/test/expire.js @@ -1,127 +1,119 @@ -(function () { - 'use strict'; +import createExpirationPolicy from "../dist/ExpressRedisCache/expire"; - var mocha = require('mocha'); - var should = require('should'); +describe("expire", () => { + it("should be a function", () => { + createExpirationPolicy.should.be.a.Function; + }); - var createExpirationPolicy = require('../lib/ExpressRedisCache/expire'); + it("should accept a number", () => { + createExpirationPolicy(1).should.be.a.Function; + }); - describe ( 'expire', function () { + it("should accept an object", () => { + createExpirationPolicy({ + xxx: -1 + }).should.be.a.Function; + }); - it ( 'should be a function', function () { - createExpirationPolicy.should.be.a.Function; - }); + it("should require an argument", () => { + createExpirationPolicy.should.throw(); + }); - it ( 'should accept a number', function () { - createExpirationPolicy(1).should.be.a.Function; - }); + it("should not accept a boolean", () => { + (function() { + createExpirationPolicy(true); + }.should.throw()); + }); - it ( 'should accept an object', function () { + it("should require a default (xxx) expiration", () => { + (function() { createExpirationPolicy({ - 'xxx': -1, - }).should.be.a.Function; - }); - - it ( 'should require an argument', function () { - createExpirationPolicy.should.throw(); - }); - - it ( 'should not accept a boolean', function () { - (function () { - createExpirationPolicy(true); - }).should.throw(); - }); - - it ( 'should require a default (xxx) expiration', function () { - (function () { - createExpirationPolicy({ - '1xx': 1, - '2xx': 2 - }); - }).should.throw(); - }); + "1xx": 1, + "2xx": 2 + }); + }.should.throw()); + }); - it ( 'should only accept two orders of wildcards', function () { - (function () { - createExpirationPolicy({ - 'xxx': -1, - '33x': 1 - }); - }).should.throw(); - }); + it("should only accept two orders of wildcards", () => { + (function() { + createExpirationPolicy({ + xxx: -1, + "33x": 1 + }); + }.should.throw()); + }); - it ( 'should only accept number values for status code specific values', function () { - (function () { - createExpirationPolicy({ - 'xxx': -1, - '33x': true - }); - }).should.throw(); - }); + it("should only accept number values for status code specific values", () => { + (function() { + createExpirationPolicy({ + xxx: -1, + "33x": true + }); + }.should.throw()); + }); - it ( 'should only accept valid status code keys', function () { - (function () { - createExpirationPolicy({ - 'xxx': -1, - '6xx': 1 - }); - }).should.throw(); - (function () { - createExpirationPolicy({ - 'xxx': -1, - '600': 1 - }); - }).should.throw(); - (function () { - createExpirationPolicy({ - 'xxx': -1, - '6': 1 - }); - }).should.throw(); - }) + it("should only accept valid status code keys", () => { + (function() { + createExpirationPolicy({ + xxx: -1, + "6xx": 1 + }); + }.should.throw()); + (function() { + createExpirationPolicy({ + xxx: -1, + "600": 1 + }); + }.should.throw()); + (function() { + createExpirationPolicy({ + xxx: -1, + "6": 1 + }); + }.should.throw()); + }); - it ( 'should return the specified value for all status codes', function () { - createExpirationPolicy(-1)(null, { statusCode: 200 }).should.equal(-1); - createExpirationPolicy(1)(null, { statusCode: 300 }).should.equal(1); - createExpirationPolicy(22)(null, { statusCode: 403 }).should.equal(22); - createExpirationPolicy(333)(null, { statusCode: 404 }).should.equal(333); - createExpirationPolicy(4444)(null, { statusCode: 500 }).should.equal(4444); - }); + it("should return the specified value for all status codes", () => { + createExpirationPolicy(-1)(null, { statusCode: 200 }).should.equal(-1); + createExpirationPolicy(1)(null, { statusCode: 300 }).should.equal(1); + createExpirationPolicy(22)(null, { statusCode: 403 }).should.equal(22); + createExpirationPolicy(333)(null, { statusCode: 404 }).should.equal(333); + createExpirationPolicy(4444)(null, { statusCode: 500 }).should.equal(4444); + }); - it ( 'should return the appropriate value for status codes', function () { - var policy = createExpirationPolicy({ - 'xxx': -1, - '1xx': 1, - '100': 100, - '2xx': 2, - '200': 200, - '4xx': 4, - '400': 400, - '403': 403, - '404': 404, - '5xx': 5, - '500': 500 - }); - policy(null, { statusCode: 500 }).should.equal(500); - policy(null, { statusCode: 501 }).should.equal(5); - policy(null, { statusCode: 404 }).should.equal(404); - policy(null, { statusCode: 403 }).should.equal(403); - policy(null, { statusCode: 400 }).should.equal(400); - policy(null, { statusCode: 480 }).should.equal(4); - policy(null, { statusCode: 200 }).should.equal(200); - policy(null, { statusCode: 201 }).should.equal(2); - policy(null, { statusCode: 100 }).should.equal(100); - policy(null, { statusCode: 101 }).should.equal(1); - policy(null, { statusCode: 300 }).should.equal(-1); + it("should return the appropriate value for status codes", () => { + let policy = createExpirationPolicy({ + xxx: -1, + "1xx": 1, + "100": 100, + "2xx": 2, + "200": 200, + "4xx": 4, + "400": 400, + "403": 403, + "404": 404, + "5xx": 5, + "500": 500 }); + policy(null, { statusCode: 500 }).should.equal(500); + policy(null, { statusCode: 501 }).should.equal(5); + policy(null, { statusCode: 404 }).should.equal(404); + policy(null, { statusCode: 403 }).should.equal(403); + policy(null, { statusCode: 400 }).should.equal(400); + policy(null, { statusCode: 480 }).should.equal(4); + policy(null, { statusCode: 200 }).should.equal(200); + policy(null, { statusCode: 201 }).should.equal(2); + policy(null, { statusCode: 100 }).should.equal(100); + policy(null, { statusCode: 101 }).should.equal(1); + policy(null, { statusCode: 300 }).should.equal(-1); + }); - it ( 'should treat status code keys as case insensitive', function () { - var policy = createExpirationPolicy({ - '1XX': 1, - 'xXx': 55 - }); - policy(null, { statusCode: 101 }).should.equal(1); - policy(null, { statusCode: 200 }).should.equal(55); + it("should treat status code keys as case insensitive", () => { + let policy = createExpirationPolicy({ + "1XX": 1, + xXx: 55 }); + policy(null, { statusCode: 101 }).should.equal(1); + policy(null, { statusCode: 200 }).should.equal(55); }); -})(); +}); diff --git a/test/express.js b/test/express.js index 3a06750..dc297c7 100644 --- a/test/express.js +++ b/test/express.js @@ -1,229 +1,211 @@ -// var path = require('path'); -var assert = require('assert'); +import request from "request"; +import child_process from "child_process"; -var mocha = require('mocha'); -var should = require('should'); -var request = require('request'); -var util = require('util'); +let spawn, express_port; -var prefix = process.env.EX_RE_CA_PREFIX || 'erct:'; -var host = process.env.EX_RE_CA_HOST || 'localhost'; -var port = process.env.EX_RE_CA_PORT || 6379; - -var spawn, - express_port, - home; - -describe ( 'test with small express server', function () { - - before(function (done) { +describe("test with small express server", () => { + before(function(done) { this.timeout(5000); - spawn = require('child_process') - .spawn('express/server.js', [], {}); + spawn = child_process.spawn("express/server.js", [], {}); - spawn.on('error', function (error) { - throw error; + spawn.on("error", error => { + console.error(error); }); - spawn.on('exit', function (status) { - console.log('Express Server exit with status ' + status); + spawn.on("exit", status => { + console.log(`Express Server exit with status ${status}`); }); - spawn.stdout.on('data', function (data) { + spawn.stdout.on("data", data => { console.log(data.toString()); - if ( /express-redis-cache test server started on port/.test(data.toString()) ) { + if ( + /express-redis-cache test server started on port/.test(data.toString()) + ) { + express_port = data + .toString() + .split(" ") + .pop() + .trim(); + done(); + } + }); + + spawn.stderr.on("data", data => { + console.log(`stderr: ${data}`); + }); + }); - express_port = data.toString().split(' ').pop().trim(); + it("should have a / route", done => { + request(`http://localhost:${express_port}`, (error, response) => { + if (error) { + throw error; + } + response.statusCode.should.equal(200); + done(); + }); + }); - done(); - } + it("should not have /foobar route", done => { + request(`http://localhost:${express_port}/foobar`, (error, response) => { + if (error) { + throw error; + } + response.statusCode.should.equal(404); + done(); }); }); - it ( 'should have a / route', function (done) { - request('http://localhost:' + express_port, - function (error, response, body) { - if ( error ) { - throw error; - } + it("/1sec route should return json with a timestamp property", done => { + let url = `http://localhost:${express_port}/1sec`; + request(url, (error, response, body) => { + if (error) { + throw error; + } + let p_body = JSON.parse(body); + // Some Mocha weirdness requires a try/catch + // or an AssertionError will crash the mocha process on error + try { response.statusCode.should.equal(200); + p_body.should.have.property("timestamp"); done(); - }); + } catch (e) { + done(e); + } + }); }); - it ( 'should not have /foobar route', function (done) { - request('http://localhost:' + express_port + "/foobar", - function (error, response, body) { - if ( error ) { - throw error; - } - response.statusCode.should.equal(404); + it("/default_expire route should return json with a timestamp property", done => { + let url = `http://localhost:${express_port}/default_expire`; + request(url, (error, response, body) => { + if (error) { + throw error; + } + let p_body = JSON.parse(body); + // Some Mocha weirdness requires a try/catch + // or an AssertionError will crash the mocha process on error + try { + response.statusCode.should.equal(200); + p_body.should.have.property("timestamp"); done(); - }); + } catch (e) { + done(e); + } + }); }); - it ( '/1sec route should return json with a timestamp property', function (done) { - var url = 'http://localhost:' + express_port + "/1sec"; - request(url, - function (error, response, body) { - if ( error ) { - throw error; - } - var p_body = JSON.parse(body); - // Some Mocha weirdness requires a try/catch - // or an AssertionError will crash the mocha process on error - try { - response.statusCode.should.equal(200); - p_body.should.have.property('timestamp'); - done(); - } catch (e) { - done(e); - } - }); + it("/never_expire route should return json with a timestamp property", done => { + let url = `http://localhost:${express_port}/never_expire`; + request(url, (error, response, body) => { + if (error) { + throw error; + } + let p_body = JSON.parse(body); + // Some Mocha weirdness requires a try/catch + // or an AssertionError will crash the mocha process on error + try { + response.statusCode.should.equal(200); + p_body.should.have.property("timestamp"); + done(); + } catch (e) { + done(e); + } + }); }); - it ( '/default_expire route should return json with a timestamp property', function (done) { - var url = 'http://localhost:' + express_port + "/default_expire"; - request(url, - function (error, response, body) { - if ( error ) { + it("/1sec route data should expire after 1 seconds", done => { + setTimeout(() => { + let url = `http://localhost:${express_port}/1sec`; + request(url, (error, response, body) => { + if (error) { throw error; } - var p_body = JSON.parse(body); + let p_body = JSON.parse(body), + timestamp = p_body.timestamp, + now_timestamp = Math.floor(Date.now() / 1000); + // Some Mocha weirdness requires a try/catch // or an AssertionError will crash the mocha process on error try { response.statusCode.should.equal(200); - p_body.should.have.property('timestamp'); + timestamp.should.be.above(now_timestamp - 1); done(); } catch (e) { done(e); } }); + }, 1100); }); - it ( '/never_expire route should return json with a timestamp property', function (done) { - var url = 'http://localhost:' + express_port + "/never_expire"; - request(url, - function (error, response, body) { - if ( error ) { + it("/default_expire route data should expire after 3 seconds", function(done) { + this.timeout(4000); // allow 5 secs to execute + setTimeout(() => { + let url = `http://localhost:${express_port}/default_expire`; + request(url, (error, response, body) => { + if (error) { throw error; } - var p_body = JSON.parse(body); + let p_body = JSON.parse(body), + timestamp = p_body.timestamp, + now_timestamp = Math.floor(Date.now() / 1000); + // Some Mocha weirdness requires a try/catch // or an AssertionError will crash the mocha process on error try { response.statusCode.should.equal(200); - p_body.should.have.property('timestamp'); + timestamp.should.be.above(now_timestamp - 3); done(); } catch (e) { done(e); } }); - }); - - it ( '/1sec route data should expire after 1 seconds', function (done) { - setTimeout(function () { - var url = 'http://localhost:' + express_port + "/1sec"; - request(url, - function (error, response, body) { - if ( error ) { - throw error; - } - var p_body = JSON.parse(body), - timestamp = p_body.timestamp, - now_timestamp = Math.floor(Date.now() / 1000); - - // Some Mocha weirdness requires a try/catch - // or an AssertionError will crash the mocha process on error - try { - response.statusCode.should.equal(200); - timestamp.should.be.above(now_timestamp - 1); - done(); - } catch (e) { - done(e); - } - }); - }, 1100); - }); - - - - it ( '/default_expire route data should expire after 3 seconds', function (done) { - this.timeout(4000); // allow 5 secs to execute - setTimeout(function () { - var url = 'http://localhost:' + express_port + "/default_expire"; - request(url, - function (error, response, body) { - if ( error ) { - throw error; - } - var p_body = JSON.parse(body), - timestamp = p_body.timestamp, - now_timestamp = Math.floor(Date.now() / 1000); - - // Some Mocha weirdness requires a try/catch - // or an AssertionError will crash the mocha process on error - try { - response.statusCode.should.equal(200); - timestamp.should.be.above(now_timestamp - 3); - done(); - } catch (e) { - done(e); - } - }); }, 3100); }); - it ( '/never_expire route data should not expire after 3 seconds', function (done) { + it("/never_expire route data should not expire after 3 seconds", function(done) { this.timeout(4000); // allow 5 secs to execute - setTimeout(function () { - var url = 'http://localhost:' + express_port + "/never_expire"; - request(url, - function (error, response, body) { - if ( error ) { - throw error; - } - var p_body = JSON.parse(body), - timestamp = p_body.timestamp, - now_timestamp = Math.floor(Date.now() / 1000); - - // Some Mocha weirdness requires a try/catch - // or an AssertionError will crash the mocha process on error - try { - response.statusCode.should.equal(200); - timestamp.should.be.below(now_timestamp - 3); - done(); - } catch (e) { - done(e); - } - }); - }, 3100); - }); - - it ( '/never_expire/delete route data should be deleted', function (done) { - var url = 'http://localhost:' + express_port + "/delete_never_expire"; - request(url, - function (error, response, body) { - if ( error ) { + setTimeout(() => { + let url = `http://localhost:${express_port}/never_expire`; + request(url, (error, response, body) => { + if (error) { throw error; } + let p_body = JSON.parse(body), + timestamp = p_body.timestamp, + now_timestamp = Math.floor(Date.now() / 1000); + // Some Mocha weirdness requires a try/catch // or an AssertionError will crash the mocha process on error try { response.statusCode.should.equal(200); - body.should.equal("count:1"); + timestamp.should.be.below(now_timestamp - 3); done(); } catch (e) { done(e); } }); + }, 3100); }); + it("/never_expire/delete route data should be deleted", done => { + let url = `http://localhost:${express_port}/delete_never_expire`; + request(url, (error, response, body) => { + if (error) { + throw error; + } + // Some Mocha weirdness requires a try/catch + // or an AssertionError will crash the mocha process on error + try { + response.statusCode.should.equal(200); + body.should.equal("count:1"); + done(); + } catch (e) { + done(e); + } + }); + }); - after(function (done) { + after(done => { process.kill(spawn.pid); done(); }); - -}); \ No newline at end of file +}); diff --git a/test/get.js b/test/get.js index 418f6a5..1b2368c 100644 --- a/test/get.js +++ b/test/get.js @@ -1,123 +1,103 @@ -(function () { +import should from "should"; +import ERC from "../dist"; - 'use strict'; +let prefix = process.env.EX_RE_CA_PREFIX || "erct:"; +let host = process.env.EX_RE_CA_HOST || "localhost"; +let port = process.env.EX_RE_CA_PORT || 6379; - var path = require('path'); - var assert = require('assert'); +let cache = new ERC({ + prefix: prefix, + host: host, + port: port +}); - var mocha = require('mocha'); - var should = require('should'); +describe("get", () => { + let error, results; - var prefix = process.env.EX_RE_CA_PREFIX || 'erct:'; - var host = process.env.EX_RE_CA_HOST || 'localhost'; - var port = process.env.EX_RE_CA_PORT || 6379; - - var _name = 'test1'; - var _body = 'test1 test1 test1'; - var _type = 'text/plain'; - - var cache = require('../')({ - prefix: prefix, - host: host, - port: port + it("should be a function", () => { + cache.get.should.be.a.Function; }); - describe ( 'get', function () { - - var error, results; - - it ( 'should be a function', function () { - cache.get.should.be.a.Function; + it("should callback", done => { + cache.get(null, ($error, $results) => { + error = $error; + results = $results; + done(); }); + }); - it ( 'should callback', function (done) { - cache.get(null, function ($error, $results) { - error = $error; - results = $results; - done(); - }); - }); + it("should not have error", () => { + should(error).be.null; + }); - it ( 'should not have error', function () { - should(error).be.null; - }); + it("should be an array", () => { + results.should.be.an.Array; + }); - it ( 'should be an array', function () { - results.should.be.an.Array; + it(" - entry which has a property name which a string", () => { + results.forEach(result => { + result.name.should.be.a.String; }); + }); - it ( ' - entry which has a property name which a string', function () { - results.forEach(function (result) { - result.name.should.be.a.String; - }); - }); - - it ( ' - entry which has a property body which a string', function () { - results.forEach(function (result) { - result.body.should.be.a.String; - }); + it(" - entry which has a property body which a string", () => { + results.forEach(result => { + result.body.should.be.a.String; }); + }); - it ( ' - entry which has a property type which a string', function () { - results.forEach(function (result) { - result.type.should.be.a.String; - }); + it(" - entry which has a property type which a string", () => { + results.forEach(result => { + result.type.should.be.a.String; }); + }); - it ( ' - entry which has a property touched which is a number which resolves to date', function () { - results.forEach(function (result) { - Number(result.touched).should.be.a.Number; + it(" - entry which has a property touched which is a number which resolves to date", () => { + results.forEach(result => { + Number(result.touched).should.be.a.Number; - new Date(Number(result.touched)) - .should.be.a.Date; - }); + new Date(Number(result.touched)).should.be.a.Date; }); + }); - it ( 'should support wildcard gets', function (done) { - cache.add('wildkey1', 'abc', - function ($error, $name, $entry) { - cache.add('wildkey2', 'def', - function ($error, $name, $entry) { - cache.get('wildkey*', function ($error, $results) { - $results.should.be.an.Array; - $results.should.have.a.lengthOf(2); - done(); - }); - }); + it("should support wildcard gets", done => { + cache.add("wildkey1", "abc", ($error, $name, $entry) => { + cache.add("wildkey2", "def", ($error, $name, $entry) => { + cache.get("wildkey*", ($error, $results) => { + $results.should.be.an.Array; + $results.should.have.a.lengthOf(2); + done(); }); + }); }); + }); - it ( 'should support specific gets without calling keys', function (done) { - - // wrap the call to keys, so we can see if it's called - var callCount = 0; - var wrap = function(fn){ - return function(){ - console.log('What!?'); - callCount++; - return fn.apply(this, arguments); - }; + it("should support specific gets without calling keys", done => { + // wrap the call to keys, so we can see if it's called + let callCount = 0; + let wrap = function(fn) { + return function() { + console.log("What!?"); + callCount++; + return fn.apply(this, arguments); }; - - cache.client.keys = wrap(cache.client.keys); - - cache.add('wildkey1', 'abc', - function ($error, $name, $entry) { - cache.add('wildkey2', 'def', - function ($error, $name, $entry) { - cache.get('wildkey1', function ($error, $results) { - try { - $results.should.be.an.Array; - $results.should.have.a.lengthOf(1); - callCount.should.equal(0); - done(); - } catch (e) { - done(e); - } - }); - }); + }; + + cache.client.keys = wrap(cache.client.keys); + + cache.add("wildkey1", "abc", ($error, $name, $entry) => { + cache.add("wildkey2", "def", ($error, $name, $entry) => { + cache.get("wildkey1", ($error, $results) => { + try { + $results.should.be.an.Array; + $results.should.have.a.lengthOf(1); + callCount.should.equal(0); + done(); + } catch (e) { + done(e); + } }); + }); }); }); - -})(); +}); diff --git a/test/route.js b/test/route.js index f94f1c1..0bdc68a 100644 --- a/test/route.js +++ b/test/route.js @@ -1,197 +1,181 @@ -(function () { - - 'use strict'; +import should from "should"; +import Domain from "domain"; +import async from "async"; +import assert from "assert"; +import ERC from "../dist"; + +let prefix = process.env.EX_RE_CA_PREFIX || "erct:"; +let host = process.env.EX_RE_CA_HOST || "localhost"; +let port = process.env.EX_RE_CA_PORT || 6379; + +let cache = new ERC({ + prefix: prefix, + host: host, + port: port +}); + +let _name = `test-route${process.pid}`; +let _expire = 60; + +/** Emulate req **/ +let req = { + originalUrl: "/index" +}; - var path = require('path'); - var assert = require('assert'); +/** Emulate res **/ +let res = { + statusCode: 200, + send: function(body) {}, + _headers: { + "content-type": "text/plain" + } +}; - var mocha = require('mocha'); - var should = require('should'); +/** Emulate next **/ +let next = function() { + // res.send(entry.body); +}; - var prefix = process.env.EX_RE_CA_PREFIX || 'erct:'; - var host = process.env.EX_RE_CA_HOST || 'localhost'; - var port = process.env.EX_RE_CA_PORT || 6379; +describe("route", () => { + let middleware, error, results; - var cache = require('../')({ - prefix: prefix, - host: host, - port: port + it("should be a function", () => { + cache.route.should.be.a.Function(); }); - var _name = 'test-route' + process.pid; - var _expire = 60; - - /** Emulate req **/ - var req = { - originalUrl: '/index' - }; - - /** Emulate res **/ - var res = { - statusCode: 200, - send: function (body) { - - }, - _headers: { - 'content-type': 'text/plain' - } - }; - - /** Emulate next **/ - var next = function () { - // res.send(entry.body); - }; - - describe ( 'route', function () { - - var middleware, error, results; - - it ( 'should be a function', function () { - cache.route.should.be.a.Function(); - }); + it("should return a function", () => { + middleware = cache.route(_name, _expire); + middleware.should.be.a.Function(); + }); - it ( 'should return a function', function () { - middleware = cache.route(_name, _expire); - middleware.should.be.a.Function(); + describe("On Calling the route", () => { + it("should call next", done => { + middleware(req, res, error => { + if (error) { + throw error; + } + res._headers["cache-control"].should.equal("max-age=60000"); + res.send("hello folks!"); + done(); + }); }); - describe('On Calling the route', function () { - - it ( 'should call next', function (done) { - middleware( - req, - res, - function (error) { - if ( error ) { - throw error; - } - res.send('hello folks!'); - done(); - }); + it("should have created the cache entry", done => { + cache.get(_name, (error, $results) => { + if (error) { + throw error; + } + $results.length.should.be.above(0); + results = $results; + done(); }); + }); - it ( 'should have created the cache entry', function (done) { - cache.get(_name, function (error, $results) { - if ( error ) { - throw error; - } - $results.length.should.be.above(0); - results = $results; - done(); + describe("cache entry", () => { + it('should be have a property "body" which is a string and equals the sent text', () => { + results.forEach(entry => { + entry.should.have.property("body").which.is.a.String(); + entry.body.should.equal("hello folks!"); }); }); - describe ( 'cache entry', function () { - - it ( 'should be have a property "body" which is a string and equals the sent text', function () { - results.forEach(function (entry) { - entry.should.have.property('body').which.is.a.String(); - entry.body.should.equal('hello folks!'); - }); - }); - - it ( 'should be have a property "type" which is a string and equals the sent type', function () { - results.forEach(function (entry) { - entry.should.have.property('type').which.is.a.String(); - entry.type.should.equal(res._headers['content-type']); - }); + it('should be have a property "type" which is a string and equals the sent type', () => { + results.forEach(entry => { + entry.should.have.property("type").which.is.a.String(); + entry.type.should.equal(res._headers["content-type"]); }); + }); - it ( ' - entry which has a property touched which is a number which, when resolved to date, is less than 2 seconds from now', function () { - results.forEach(function (entry) { - Number(entry.touched).should.be.a.Number(); + it(" - entry which has a property touched which is a number which, when resolved to date, is less than 2 seconds from now", () => { + results.forEach(entry => { + Number(entry.touched).should.be.a.Number(); - var date = new Date(Number(entry.touched)); + let date = new Date(Number(entry.touched)); - ( (Date.now() - date) ).should.be.below(2000); - }); + (Date.now() - date).should.be.below(2000); }); + }); - it ( ' - entry which has a property expire which equals sent expire', function () { - results.forEach(function (entry) { - should(+entry.expire).equal(_expire); - }); + it(" - entry which has a property expire which equals sent expire", () => { + results.forEach(entry => { + should(+entry.expire).equal(_expire); }); }); }); }); - describe ( 'binaryroute', function () { - - var middleware, error, results; +}); +describe("binaryroute", () => { + let middleware, error, results; - it ( 'should be a function', function () { - cache.route.should.be.a.Function(); - }); - - it ( 'should return a function', function () { - middleware = cache.route({name: 'binary', expire: _expire, binary: true}); - middleware.should.be.a.Function(); - }); + it("should be a function", () => { + cache.route.should.be.a.Function(); + }); - describe('On Calling the route', function () { + it("should return a function", () => { + middleware = cache.route({ name: "binary", expire: _expire, binary: true }); + middleware.should.be.a.Function(); + }); - it ( 'should call next', function (done) { - middleware( - req, - res, - function (error) { - if ( error ) { - throw error; - } + describe("On Calling the route", () => { + it("should call next", done => { + middleware(req, res, error => { + if (error) { + throw error; + } - res.send(new Buffer('hello folks!', 'binary')); - done(); - }); + res.send(Buffer.from("hello folks!").toString("base64")); + done(); }); + }); - it ( 'should have created the cache entry', function (done) { - cache.get('binary', function (error, $results) { - if ( error ) { - throw error; - } - $results.length.should.be.above(0); - results = $results; - done(); - }); + it("should have created the cache entry", done => { + cache.get("binary", (error, $results) => { + if (error) { + throw error; + } + $results.length.should.be.above(0); + results = $results; + done(); }); + }); - describe ( 'cache entry', function () { - - it ( 'should be have a property "body" which is a base64 string and decodes to sent text', function () { - results.forEach(function (entry) { - entry.should.have.property('body').which.is.a.String(); - entry.body.should.equal('aGVsbG8gZm9sa3Mh'); //aGVsbG8gZm9sa3Mh = 'hello folks!' in base64 - var decodedString = new Buffer(entry.body, 'base64').toString('utf8'); - decodedString.should.equal('hello folks!'); - }); + describe("cache entry", () => { + it('should be have a property "body" which is a base64 string and decodes to sent text', () => { + results.forEach(entry => { + entry.should.have.property("body").which.is.a.String(); + entry.body.should.equal("aGVsbG8gZm9sa3Mh"); //aGVsbG8gZm9sa3Mh = 'hello folks!' in base64 + let decodedString = Buffer.from(entry.body, "base64").toString( + "utf8" + ); + decodedString.should.equal("hello folks!"); }); + }); - it ( 'should be have a property "type" which is a string and equals the sent type', function () { - results.forEach(function (entry) { - entry.should.have.property('type').which.is.a.String(); - entry.type.should.equal(res._headers['content-type']); - }); + it('should be have a property "type" which is a string and equals the sent type', () => { + results.forEach(entry => { + entry.should.have.property("type").which.is.a.String(); + entry.type.should.equal(res._headers["content-type"]); }); + }); - it ( ' - entry which has a property touched which is a number which, when resolved to date, is less than 2 seconds from now', function () { - results.forEach(function (entry) { - Number(entry.touched).should.be.a.Number(); + it(" - entry which has a property touched which is a number which, when resolved to date, is less than 2 seconds from now", () => { + results.forEach(entry => { + Number(entry.touched).should.be.a.Number(); - var date = new Date(Number(entry.touched)); + let date = new Date(Number(entry.touched)); - ( (Date.now() - date) ).should.be.below(2000); - }); + (Date.now() - date).should.be.below(2000); }); + }); - it ( ' - entry which has a property expire which equals sent expire', function () { - results.forEach(function (entry) { - should(+entry.expire).equal(_expire); - }); + it(" - entry which has a property expire which equals sent expire", () => { + results.forEach(entry => { + should(+entry.expire).equal(_expire); }); }); }); }); -})(); +}); /** @@ -209,78 +193,66 @@ **/ -module.exports = function (cb) { - - if ( typeof cb !== 'function' ) { - throw new Error('Missing callback'); +module.exports = function(cb) { + if (typeof cb !== "function") { + throw new Error("Missing callback"); } - var cache = this; - - var domain = require('domain').create(); - - var cacheEntry = '/path'; - - domain.on('error', function (error) { - cb(error); - }); - - domain.run(function () { - - var assert = require('./assert'); - - require('async').parallel( - /* for each new cache **/ - cache.newCaches + let cache = this; - /** if it is a route cache */ - .filter(function (entry) { - return !!( /^\/route_/.test(entry.name) ); - }) + async.parallel( + /* for each new cache **/ + cache.newCaches - .map(function (entry) { - return function (then) { - var name = this.name; - var entry = this.entry; + /** if it is a route cache */ + .filter(entry => { + return !!/^\/route_/.test(entry.name); + }) - console.log(); - console.log(' Testing cache.route'.bold.blue, name, entry); - console.log(); + .map(entry => { + return function(then) { + let name = this.name; + let entry = this.entry; - /** Emulate req **/ - var req = { - path: name - }; + console.log(); + console.log(" Testing cache.route".bold.blue, name, entry); + console.log(); - /** Emulate res **/ - var res = { - statusCode: 200, - send: function (body) { - assert('it should be the same message', body === entry.body); + /** Emulate req **/ + let req = { + path: name + }; - then(); - } - }; + /** Emulate res **/ + let res = { + statusCode: 200, + send: function(body) { + assert("it should be the same message", body === entry.body); - /** Emulate next **/ - var next = function () { - assert('There should be a response variable', !!res.expressRedisCache); - - res.send(entry.body); - }; + then(); + } + }; - var router = cache.route(); + /** Emulate next **/ + let next = function() { + assert( + "There should be a response variable", + !!res.expressRedisCache + ); - assert('it should be a function', typeof router === 'function'); + res.send(entry.body); + }; - /** Emulate a HTTP request **/ + let router = cache.route(); - router.apply(cache, [req, res, next]); + assert("it should be a function", typeof router === "function"); - }.bind(entry); - }), + /** Emulate a HTTP request **/ - cb); + router.apply(cache, [req, res, next]); + }.bind(entry); + }), - }); + cb + ); };