Skip to content

Commit

Permalink
Change the default value of the cachePromiseRejection option to `tr…
Browse files Browse the repository at this point in the history
…ue` (#36)
  • Loading branch information
fregante authored and sindresorhus committed May 17, 2019
1 parent 10f13c0 commit 70707ae
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ declare namespace mem {
/**
Cache rejected promises.
@default false
@default true
*/
readonly cachePromiseRejection?: boolean;
}
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const mem = (fn, options) => {
options = Object.assign({
cacheKey: defaultCacheKey,
cache: new Map(),
cachePromiseRejection: false
cachePromiseRejection: true
}, options);

if (typeof options.maxAge === 'number') {
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Use a different cache storage. Must implement the following methods: `.has(key)`
##### cachePromiseRejection

Type: `boolean`<br>
Default: `false`
Default: `true`

Cache rejected promises.

Expand Down
4 changes: 3 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ test('promise support', async t => {
t.is(await memoized(10), 1);
});

test('do not cache rejected promises', async t => {
test('cachePromiseRejection option', async t => {
let i = 0;
const memoized = mem(async () => {
i++;
Expand All @@ -172,6 +172,8 @@ test('do not cache rejected promises', async t => {
}

return i;
}, {
cachePromiseRejection: false
});

await t.throwsAsync(memoized(), 'foo bar');
Expand Down

0 comments on commit 70707ae

Please sign in to comment.