-
Notifications
You must be signed in to change notification settings - Fork 15
feat: drop node4 support #39
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"extends": "groupon/node4" | ||
"extends": "groupon/node6" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
language: node_js | ||
node_js: | ||
- 4.6.1 | ||
- 6.11.5 | ||
- 8.9.0 | ||
- v6.14.3 | ||
- v8.11.3 | ||
- v10.5.0 | ||
deploy: | ||
- provider: script | ||
script: ./node_modules/.bin/nlm release | ||
skip_cleanup: true | ||
'on': | ||
branch: master | ||
node: 8.9.0 | ||
node: 10.5.0 | ||
services: memcached |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,33 +33,36 @@ | |
'use strict'; | ||
|
||
const Bluebird = require('bluebird'); | ||
const _ = require('lodash'); | ||
const util = require('util'); | ||
|
||
const Cache = require('./cache'); | ||
|
||
let namedCaches = Object.create(null); | ||
const namedCaches = new Map(); | ||
|
||
const getName = util.deprecate(function getName(name) { | ||
return name || 'default'; | ||
}, 'Unnamed caches and caches with non-string names are deprecated.'); | ||
const getName = util.deprecate( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This turns a previously named function into something that won't have a meaningful |
||
name => name || 'default', | ||
'Unnamed caches and caches with non-string names are deprecated.' | ||
); | ||
|
||
function cached(name, options) { | ||
if (typeof name !== 'string') { | ||
name = getName(name); | ||
} | ||
|
||
if (!(name in namedCaches)) { | ||
namedCaches[name] = cached.createCache( | ||
_.extend( | ||
{ | ||
name: name, | ||
}, | ||
options || {} | ||
if (!namedCaches.has(name)) { | ||
namedCaches.set( | ||
name, | ||
cached.createCache( | ||
Object.assign( | ||
{ | ||
name: name, | ||
}, | ||
options || {} | ||
) | ||
) | ||
); | ||
} | ||
return namedCaches[name]; | ||
return namedCaches.get(name); | ||
} | ||
module.exports = cached; | ||
|
||
|
@@ -68,17 +71,17 @@ cached.createCache = function createCache(options) { | |
}; | ||
|
||
cached.dropNamedCaches = function dropNamedCaches() { | ||
namedCaches = Object.create(null); | ||
namedCaches.clear(); | ||
return cached; | ||
}; | ||
|
||
cached.dropNamedCache = function dropNamedCache(name) { | ||
delete namedCaches[name]; | ||
namedCaches.delete(name); | ||
return cached; | ||
}; | ||
|
||
cached.knownCaches = function knownCaches() { | ||
return Object.keys(namedCaches); | ||
return [...namedCaches.keys()]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: should we return a MapIterator instead ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We wanted to keep the interface slim. Exposing a map iterator would lock us into using a |
||
}; | ||
|
||
cached.deferred = function deferred(fn) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,6 @@ | |
'use strict'; | ||
|
||
const Bluebird = require('bluebird'); | ||
const _ = require('lodash'); | ||
|
||
const util = require('./util'); | ||
|
||
|
@@ -77,10 +76,12 @@ function getOrElse(cache, key, val, opts) { | |
|
||
function verifyFreshness(wrappedValue) { | ||
const hit = !!wrappedValue; | ||
const expired = util.isExpired(wrappedValue && wrappedValue.b); | ||
let loadingNewValue = cache.staleOrPending[key] !== undefined; | ||
|
||
if ((!hit || expired) && !loadingNewValue) { | ||
if ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason why we went back to a huge if condition here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so the reason for the change is the likelihood of each part on the condition as well as calling functions / getting values
|
||
!loadingNewValue && | ||
(!hit || util.isExpired(wrappedValue && wrappedValue.b)) | ||
) { | ||
cache.staleOrPending[key] = refreshValue(); | ||
loadingNewValue = true; | ||
} | ||
|
@@ -96,7 +97,7 @@ function getOrElse(cache, key, val, opts) { | |
|
||
return cache | ||
._getWrapped(key) | ||
.catch(_.constant(null)) | ||
.catch(() => null) | ||
.then(verifyFreshness); | ||
} | ||
module.exports = getOrElse; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import assert from 'assertive'; | ||
import Bluebird from 'bluebird'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh, we should undo this eventually. Completely forgot that we were using babel script modules in this project. Good reminder. :) |
||
import { identity } from 'lodash'; | ||
const identity = val => val; | ||
|
||
import Cache from '../lib/cache'; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note: Using
function
would have been shorter and wouldn't have closed over the weird module-scopethis
.