Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes #5

Merged
merged 10 commits into from
Feb 13, 2019
Merged

Various fixes #5

merged 10 commits into from
Feb 13, 2019

Conversation

msluther
Copy link
Contributor

(This was built on top of #4)

Fixes include:

  1. Catch unhandled promise rejection for when cache is attempted to refresh, but state data was returned. ("logs" to diagnostics)
  2. Actually allowing maxAge and maxStaleness to be sent along with calls to get as implied by the unit tests and called out in the README.
  3. Various minor JSDoc fixes

@@ -1,5 +1,8 @@
# Change Log

- [#5] Allow for call-level age overrides as specified in the README.
- [#4] Bump various dev-dependencies
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this PR make #4 useless?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, unless we want them to be separate and more targeted in scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the merge separately.

};

if (shouldCache && typeof shouldCache !== 'function') {
const { shouldCache = this.shouldCache } = opts;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be stylistically consistent, just use getValue again

const shouldCache = getValue(opts, 'shouldCache', this.shouldCache);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

test/index.test.js Outdated Show resolved Hide resolved
test/index.test.js Outdated Show resolved Hide resolved
test/index.test.js Outdated Show resolved Hide resolved
test/index.test.js Outdated Show resolved Hide resolved
* @param {ShouldCache} [opts.shouldCache=()=>true] - Function to determine whether to not we should cache the result
* @param {Cache[]} opts.caches - An Array of cache objects. See `./fs` and `./memory` for sample caches.
* @param {Object} opts Options for the Client instance
* @param {Number} [opts.maxAge=600,000] The duration, in milliseconds, before a cached item expires

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comma should probably be removed here, as it isn't in the actual default. (We might want to include a version of the default with the comma in the description for readability).

* @returns {Any} The value of the property
*/
function getValue(opts, key, defaultValue) {
if (key in opts) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a must, but could be condensed:

return (key in opts) ? opts[key] : defaultValue;

*
* @async
* @returns {Promise<GetResult>} a Promise which resolves to an object containing
* a `value` property and a `fromCache` boolean indicator.
*/
async get(key, opts, updateFn) {
opts = opts || {};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not put the default on the argument?

async get(key, opts = {}, updateFn)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it's an awkward API and requires you to do:

.get(myKey, undefined, someFn);

since passing a null doesn't invoke the param default.

* @param {String} [opts.maxAge] The duration in milliseconds before a cached item expires
* @param {Number} [opts.maxStaleness=0] The duration, in milliseconds, in which expired cache items are still served
* @param {ShouldCache} [opts.shouldCache] A function to determine whether or not we should cache the item
* @param {UpdateFn} updateFn async function that defines how to get a new value
*
* @async
* @returns {Promise<GetResult>} a Promise which resolves to an object containing
* a `value` property and a `fromCache` boolean indicator.
*/
async get(key, opts, updateFn) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like optional-options could be used to avoid having to pass in an empty object. 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not a callback though, and while it has the same shape as what optional-options wants, its semantically different. Really the right thing to do is making a breaking change and reverse the order of the params. We should consider doing that at some point. Not sure its warranted just yet though. something to bear in mind (I'll open an issue)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lib/multi-level.js Outdated Show resolved Hide resolved
@msluther msluther merged commit dac5651 into master Feb 13, 2019
@msluther msluther deleted the fix-file-system-cache branch October 29, 2021 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants