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.0.3 to 1.0.4

8

index.js

@@ -1,2 +0,2 @@

module.exports = function cashcow (fetch, hydrate) {
module.exports = function cashcow (get, populate) {
var farm = {}

@@ -6,3 +6,3 @@

if (farm[egg]) return farm[egg]
farm[egg] = fetch(egg).then(moo)
farm[egg] = get(egg).then(moo)
return farm[egg].catch(cowpat)

@@ -12,7 +12,7 @@

if (typeof yolk !== 'undefined') return mop(yolk)
return hydrate(egg).then(huzzah)
return populate(egg).then(huzzah)
}
function huzzah () {
return fetch(egg).then(mop)
return get(egg).then(mop)
}

@@ -19,0 +19,0 @@

{
"name": "cashcow",
"version": "1.0.3",
"version": "1.0.4",
"description": "cashcow is a cache fetcher that pools consumers and minimises memory usage",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -24,4 +24,4 @@ # ![cashcow](https://cloud.githubusercontent.com/assets/640611/16666936/be6cfe96-4481-11e6-9962-44e7bbe6a537.png)

- fetch(key) a function that gets value from cache and returns a promise for that value
- hydrate(key) a function that gets the value for real and hydrates the cache, returning a promise that resolves when complete
- get(key) a function that gets value from cache and returns a promise for that value
- populate(key) a function that populates the cache, returning a promise that resolves when complete

@@ -28,0 +28,0 @@ ## installation

@@ -7,7 +7,7 @@ var Promise = require('es6-promise').Promise

function fetch (key) {
function get (key) {
return Promise.resolve(cache[key])
}
function hydrate (key, value) {
function populate (key, value) {
return new Promise(function resolver (resolve, reject) {

@@ -22,5 +22,5 @@ cache[key] = db[key]

cache: cache,
fetch: sandbox.spy(fetch),
hydrate: sandbox.spy(hydrate)
get: sandbox.spy(get),
populate: sandbox.spy(populate)
}
}

@@ -8,3 +8,3 @@ var Promise = require('es6-promise').Promise

describe('cowFetch', function () {
var sandbox, helpers, db, cache, hydrate, fetch, cowFetch
var sandbox, helpers, db, cache, get, populate, cowFetch

@@ -16,5 +16,5 @@ beforeEach(function () {

cache = helpers.cache
hydrate = helpers.hydrate
fetch = helpers.fetch
cowFetch = cashcow(fetch, hydrate)
populate = helpers.populate
get = helpers.get
cowFetch = cashcow(get, populate)
})

@@ -31,11 +31,11 @@

it('should try to fetch from cache', function () {
it('should try to get from cache', function () {
return cowFetch('a').then(() => {
expect(fetch).was.calledOnce()
expect(get).was.calledOnce()
})
})
it('should not hydrate', function () {
it('should not populate', function () {
return cowFetch('a').then(() => {
expect(hydrate).was.notCalled()
expect(populate).was.notCalled()
})

@@ -56,8 +56,8 @@ })

]).then(function () {
expect(fetch).was.calledOnce()
expect(get).was.calledOnce()
})
})
it('should propagate rejected promise to all consumers if fetch fails', function () {
cowFetch = cashcow(reject, hydrate)
it('should propagate rejected promise to all consumers if get fails', function () {
cowFetch = cashcow(reject, populate)
return Promise.all([

@@ -81,3 +81,3 @@ catcher(cowFetch('a')),

.onSecondCall().returns(Promise.resolve(cache.a))
cowFetch = cashcow(eventuallyWorks, hydrate)
cowFetch = cashcow(eventuallyWorks, populate)
var firstFetch = catcher(cowFetch('a'))

@@ -101,11 +101,11 @@ return Promise.all([

it('should try to fetch from cache', function () {
it('should try to get from cache', function () {
return cowFetch('a').then(() => {
expect(fetch).was.called()
expect(get).was.called()
})
})
it('should hydrate', function () {
it('should populate', function () {
return cowFetch('a').then(() => {
expect(hydrate).was.calledOnce()
expect(populate).was.calledOnce()
expect(cache.a).to.eql(1)

@@ -115,5 +115,5 @@ })

it('should try to fetch from cache again', function () {
it('should try to get from cache again', function () {
return cowFetch('a').then(() => {
expect(fetch).was.calledTwice()
expect(get).was.calledTwice()
})

@@ -134,9 +134,9 @@ })

]).then(function () {
expect(fetch).was.calledTwice()
expect(hydrate).was.calledOnce()
expect(get).was.calledTwice()
expect(populate).was.calledOnce()
})
})
it('should propagate rejected promise to all consumers if hydrate fails', function () {
cowFetch = cashcow(fetch, reject)
it('should propagate rejected promise to all consumers if populate fails', function () {
cowFetch = cashcow(get, reject)
return Promise.all([

@@ -155,3 +155,3 @@ catcher(cowFetch('a')),

it('should recover if hydrate starts working again', function () {
it('should recover if populate starts working again', function () {
var callCount = 0

@@ -163,3 +163,3 @@ var eventuallyWorks = sinon.spy(function () {

})
cowFetch = cashcow(fetch, eventuallyWorks)
cowFetch = cashcow(get, eventuallyWorks)
var firstFetch = catcher(cowFetch('a'))

@@ -179,4 +179,4 @@ return Promise.all([

it('should propagate rejected promise to all consumers if fetch fails', function () {
cowFetch = cashcow(reject, hydrate)
it('should propagate rejected promise to all consumers if get fails', function () {
cowFetch = cashcow(reject, populate)
return Promise.all([

@@ -195,3 +195,3 @@ catcher(cowFetch('a')),

it('should recover if fetch starts working again', function () {
it('should recover if get starts working again', function () {
var eventuallyWorks = sinon.stub()

@@ -201,3 +201,3 @@ eventuallyWorks

.onSecondCall().returns(Promise.resolve(db.a))
cowFetch = cashcow(eventuallyWorks, hydrate)
cowFetch = cashcow(eventuallyWorks, populate)
var firstFetch = cowFetch('a').then(function (err) {

@@ -204,0 +204,0 @@ return err

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