Skip to content

Commit

Permalink
perf: call and reuse cacheKeyFn only when it is needed (if caching)
Browse files Browse the repository at this point in the history
  • Loading branch information
abendi committed Jun 9, 2023
1 parent d336bd1 commit 965c884
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ class DataLoader<K, V, C = K> {

const batch = getCurrentBatch(this);
const cacheMap = this._cacheMap;
const cacheKey = this._cacheKeyFn(key);
let cacheKey;

// If caching and there is a cache-hit, return cached Promise.
if (cacheMap) {
cacheKey = this._cacheKeyFn(key);
const cachedPromise = cacheMap.get(cacheKey);
if (cachedPromise) {
const cacheHits = batch.cacheHits || (batch.cacheHits = []);
Expand Down

0 comments on commit 965c884

Please sign in to comment.