async-cache-dedupe
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -87,3 +87,3 @@ 'use strict' | ||
buildPromise (query, args, key) { | ||
query.promise = this.func(args) | ||
query.promise = this.func(args, key) | ||
// we fork the promise chain on purpose | ||
@@ -90,0 +90,0 @@ query.promise.catch(() => this.ids.set(key, undefined)) |
{ | ||
"name": "async-cache-dedupe", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "An async deduping cache", | ||
@@ -11,3 +11,3 @@ "main": "index.js", | ||
"type": "git", | ||
"url": "git+https://github.com/mcollina/async-dedupe-cache.git" | ||
"url": "git+https://github.com/mcollina/async-cache-dedupe.git" | ||
}, | ||
@@ -14,0 +14,0 @@ "keywords": [ |
@@ -56,3 +56,3 @@ # async-cache-dedupe | ||
### `cache.define(name[, opts], original(arg))` | ||
### `cache.define(name[, opts], original(arg, cacheKey))` | ||
@@ -68,3 +68,4 @@ Define a new function to cache of the given `name`. | ||
The `define` method adds a `cache[name]` function that will call the `original` function if the result is not present | ||
in the cache. The cache key for `arg` is computed using [`safe-stable-stringify`](https://www.npmjs.com/package/safe-stable-stringify). | ||
in the cache. The cache key for `arg` is computed using [`safe-stable-stringify`](https://www.npmjs.com/package/safe-stable-stringify) | ||
and it is passed as the `cacheKey` argument to the original function. | ||
@@ -71,0 +72,0 @@ ### `cache.clear([name], [arg])` |
@@ -6,2 +6,3 @@ 'use strict' | ||
const { AsyncLocalStorage } = require('async_hooks') | ||
const stringify = require('safe-stable-stringify') | ||
@@ -12,3 +13,3 @@ const kValues = require('../symbol') | ||
// plan verifies that fetchSomething is called only once | ||
t.plan(3) | ||
t.plan(5) | ||
@@ -19,4 +20,5 @@ const cache = new Cache() | ||
cache.define('fetchSomething', async (query) => { | ||
cache.define('fetchSomething', async (query, cacheKey) => { | ||
t.equal(query, expected.shift()) | ||
t.equal(stringify(query), cacheKey) | ||
return { k: query } | ||
@@ -117,3 +119,3 @@ }) | ||
// plan verifies that fetchSomething is called only once | ||
t.plan(3) | ||
t.plan(5) | ||
@@ -127,4 +129,6 @@ const cache = new Cache() | ||
cache.define('fetchSomething', async (query) => { | ||
cache.define('fetchSomething', async (query, cacheKey) => { | ||
t.same(query, expected.shift()) | ||
t.equal(stringify(query), cacheKey) | ||
return { k: query } | ||
@@ -131,0 +135,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16698
481
78