diff --git a/src/index.js b/src/index.js index 1fffbd6..d3f8ed5 100644 --- a/src/index.js +++ b/src/index.js @@ -81,10 +81,11 @@ class DataLoader { 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 = []);