cache-point
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -5,3 +5,16 @@ 'use strict' | ||
// endure a 3s wait for the result | ||
// The first invocation will take 3s, the rest instantaneous. | ||
// outputs: 'result' | ||
getData('some input') | ||
.then(console.log) | ||
// cache.read() will resolve on hit, reject on miss. | ||
function getData (input) { | ||
return cache | ||
.read(input) | ||
.catch(() => expensiveOperation(input)) | ||
} | ||
// The expensive operation we're aiming to avoid, | ||
// (3 second cost per invocation) | ||
function expensiveOperation (input) { | ||
@@ -16,14 +29,1 @@ return new Promise((resolve, reject) => { | ||
} | ||
// cache.read() will resolve on hit, reject on miss. | ||
function getData (input) { | ||
return cache | ||
.read(input) | ||
.catch(() => expensiveOperation(input)) | ||
} | ||
// The first invocation will take 3s, the rest instantaneous. | ||
getData('some input') | ||
.then(console.log) | ||
// outputs: 'result' |
@@ -13,3 +13,17 @@ 'use strict' | ||
* | ||
* // endure a 3s wait for the result | ||
* // The first invocation will take 3s, the rest instantaneous. | ||
* // outputs: 'result' | ||
* getData('some input') | ||
* .then(console.log) | ||
* | ||
* // check the cache for output generated with this input. | ||
* // cache.read() will resolve on hit, reject on miss. | ||
* function getData (input) { | ||
* return cache | ||
* .read(input) | ||
* .catch(() => expensiveOperation(input)) | ||
* } | ||
* | ||
* // The expensive operation we're aiming to avoid, | ||
* // (3 second cost per invocation) | ||
* function expensiveOperation (input) { | ||
@@ -24,16 +38,2 @@ * return new Promise((resolve, reject) => { | ||
* } | ||
* | ||
* // check the cache for output generated with this input. | ||
* // cache.read() will resolve on hit, reject on miss. | ||
* function getData (input) { | ||
* return cache | ||
* .read(input) | ||
* .catch(() => expensiveOperation(input)) | ||
* } | ||
* | ||
* // The first invocation will take 3s, the rest instantaneous. | ||
* getData('some input') | ||
* .then(console.log) | ||
* | ||
* // outputs: 'result' | ||
*/ | ||
@@ -130,3 +130,3 @@ | ||
/** | ||
* Used internally to convert a key value into a hex checksum. Override if for some reason you need a different hashing strategy. | ||
* Used internally to convert a key value into a hex checksum. Override if for some reason you need a different hashing strategy. | ||
* @param {*} - One or more values to index the data, e.g. a request object or set of function args. | ||
@@ -133,0 +133,0 @@ * @returns {string} |
{ | ||
"name": "cache-point", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "Simple, filesystem-backed memoisation cache.", | ||
@@ -27,2 +27,3 @@ "repository": "https://github.com/75lb/cache-point.git", | ||
"core-assert": "~0.2.0", | ||
"jsdoc-to-markdown": "^2.0.0-alpha.0", | ||
"test-runner": "~0.1.8" | ||
@@ -29,0 +30,0 @@ }, |
@@ -17,3 +17,17 @@ [![view on npm](http://img.shields.io/npm/v/cache-point.svg)](https://www.npmjs.org/package/cache-point) | ||
// endure a 3s wait for the result | ||
// The first invocation will take 3s, the rest instantaneous. | ||
// outputs: 'result' | ||
getData('some input') | ||
.then(console.log) | ||
// check the cache for output generated with this input. | ||
// cache.read() will resolve on hit, reject on miss. | ||
function getData (input) { | ||
return cache | ||
.read(input) | ||
.catch(() => expensiveOperation(input)) | ||
} | ||
// The expensive operation we're aiming to avoid, | ||
// (3 second cost per invocation) | ||
function expensiveOperation (input) { | ||
@@ -28,16 +42,2 @@ return new Promise((resolve, reject) => { | ||
} | ||
// check the cache for output generated with this input. | ||
// cache.read() will resolve on hit, reject on miss. | ||
function getData (input) { | ||
return cache | ||
.read(input) | ||
.catch(() => expensiveOperation(input)) | ||
} | ||
// The first invocation will take 3s, the rest instantaneous. | ||
getData('some input') | ||
.then(console.log) | ||
// outputs: 'result' | ||
``` | ||
@@ -149,1 +149,2 @@ | ||
© 2016 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown). | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21370
425
148
4