From c1f43cb972bacd9cd8d8e55207abca9585847581 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Fri, 10 Feb 2017 15:54:06 +0200 Subject: [PATCH] Cache resolve-rc results --- src/fs-cache.js | 4 ++-- src/resolve-rc.js | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/fs-cache.js b/src/fs-cache.js index 206c74a3..05b77130 100644 --- a/src/fs-cache.js +++ b/src/fs-cache.js @@ -15,6 +15,8 @@ const os = require("os"); const path = require("path"); const zlib = require("zlib"); +let defaultCacheDirectory = null; // Lazily instantiated when needed + /** * Read the contents from the compressed file. * @@ -162,8 +164,6 @@ const handleCache = function(directory, params, callback) { * }); */ -var defaultCacheDirectory = null; // Lazily instantiated when needed - module.exports = function(params, callback) { let directory; diff --git a/src/resolve-rc.js b/src/resolve-rc.js index 30b84f8b..504ce8f2 100644 --- a/src/resolve-rc.js +++ b/src/resolve-rc.js @@ -10,6 +10,8 @@ const path = require("path"); const exists = require("./utils/exists")({}); const read = require("./utils/read")({}); +const cache = {}; + const find = function find(start, rel) { const file = path.join(start, rel); @@ -27,6 +29,10 @@ const find = function find(start, rel) { module.exports = function(loc, rel) { rel = rel || ".babelrc"; + const cacheKey = "" + loc + "/" + rel; + if (cacheKey in cache) { + return cache[cacheKey]; + } - return find(loc, rel); + return (cache[cacheKey] = find(loc, rel)); };