Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cashcow

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cashcow - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

2

package.json
{
"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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc