Comparing version 1.2.1 to 1.2.2
{ | ||
"name": "cashcow", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "cashcow is a smart cache fetcher that pools consumers and minimises memory usage", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -21,5 +21,19 @@ # ![cashcow](https://cloud.githubusercontent.com/assets/640611/16708914/d14dee66-45f9-11e6-9334-a153eeb9144f.png) | ||
```js | ||
// scenario 1: lazy population of individual cache keys | ||
var cashcow = require('cashcow') | ||
var cowFetch = cashcow(get, populate) | ||
function get (key) { | ||
return myCache.get(key) | ||
} | ||
function populate (key) { | ||
return fetchFromSource(key).then(function (val) { | ||
return myCache.set(key, val) | ||
}) | ||
} | ||
// usage | ||
cowFetch('mything') // populates cache then returns value from cache | ||
@@ -36,11 +50,25 @@ cowFetch('mything') // combined with previous fetch | ||
// scenario 2: lazy population of entire cache | ||
var cashcow = require('cashcow') | ||
var cowFetch = cashcow(populate) | ||
function get (key) { | ||
return myCustomCache.get(key) | ||
return myCache.get(key).then(function (val) { | ||
if (!val) return cowFetch().then(() => get(key)) | ||
}) | ||
} | ||
function populate (key) { | ||
return fetchFromSource(key).then(function (val) { | ||
return myCustomCache.set(key, val) | ||
}) | ||
return fetchAllFromSource().then(myCache.hydrateAll) | ||
} | ||
//usage | ||
get(key) // gets from cache, populates entire cache | ||
get(key) // call to populate combined with previous call | ||
get(key).then(function (val) { | ||
// value fetched straight from cache | ||
get(key) // value fetched straight from cache | ||
}) | ||
``` | ||
@@ -47,0 +75,0 @@ |
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
13572
87