dataloader
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -180,2 +180,24 @@ | ||
} | ||
/** | ||
* Adds the provied key and value to the cache. If the key already exists, no | ||
* change is made. Returns itself for method chaining. | ||
*/ | ||
}, { | ||
key: 'prime', | ||
value: function prime(key, value) { | ||
var cacheKeyFn = this._options && this._options.cacheKeyFn; | ||
var cacheKey = cacheKeyFn ? cacheKeyFn(key) : key; | ||
// Only add the key if it does not already exist. | ||
if (this._promiseCache.get(cacheKey) === undefined) { | ||
// Cache a rejected promise if the value is an Error, in order to match | ||
// the behavior of load(key). | ||
var promise = value instanceof Error ? Promise.reject(value) : Promise.resolve(value); | ||
this._promiseCache.set(cacheKey, promise); | ||
} | ||
return this; | ||
} | ||
}]); | ||
@@ -182,0 +204,0 @@ |
{ | ||
"name": "dataloader", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A data loading utility to reduce requests to a backend via batching and caching.", | ||
@@ -45,3 +45,3 @@ "contributors": [ | ||
"babel-core": "5.8.22", | ||
"babel-eslint": "4.1.6", | ||
"babel-eslint": "4.1.8", | ||
"chai": "3.4.1", | ||
@@ -48,0 +48,0 @@ "coveralls": "2.11.6", |
@@ -199,3 +199,9 @@ # DataLoader | ||
##### `prime(key, value)` | ||
Primes the cache with the provided key and value. If the key already exists, no | ||
change is made. (To forcefully prime the cache, clear the key first with | ||
`loader.clear(key).prime(key, value)`.) Returns itself for method chaining. | ||
## Using with GraphQL | ||
@@ -411,4 +417,9 @@ | ||
## Video Source Code Walkthrough | ||
**DataLoader Source Code Walkthrough (YouTube):** | ||
<a href="https://youtu.be/OQTnXNCDywA" target="_blank" alt="DataLoader Source Code Walkthrough"><img src="https://img.youtube.com/vi/OQTnXNCDywA/0.jpg" /></a> | ||
[@schrockn]: https://github.com/schrockn | ||
@@ -415,0 +426,0 @@ [Map]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map |
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
29357
244
432