From 70707aebaf7819ca6b33f89f2c9bf342738706b2 Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Sat, 18 May 2019 01:11:45 +0800 Subject: [PATCH] Change the default value of the `cachePromiseRejection` option to `true` (#36) --- index.d.ts | 2 +- index.js | 2 +- readme.md | 2 +- test.js | 4 +++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index 86acff4..172baa5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -36,7 +36,7 @@ declare namespace mem { /** Cache rejected promises. - @default false + @default true */ readonly cachePromiseRejection?: boolean; } diff --git a/index.js b/index.js index 5669a0a..f76e983 100644 --- a/index.js +++ b/index.js @@ -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') { diff --git a/readme.md b/readme.md index 65f10bf..e548979 100644 --- a/readme.md +++ b/readme.md @@ -115,7 +115,7 @@ Use a different cache storage. Must implement the following methods: `.has(key)` ##### cachePromiseRejection Type: `boolean`
-Default: `false` +Default: `true` Cache rejected promises. diff --git a/test.js b/test.js index d1b692c..a85db05 100644 --- a/test.js +++ b/test.js @@ -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++; @@ -172,6 +172,8 @@ test('do not cache rejected promises', async t => { } return i; + }, { + cachePromiseRejection: false }); await t.throwsAsync(memoized(), 'foo bar');