Skip to content

Commit

Permalink
Cache resolve-rc results
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Feb 10, 2017
1 parent 4bac112 commit c1f43cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/fs-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -162,8 +164,6 @@ const handleCache = function(directory, params, callback) {
* });
*/

var defaultCacheDirectory = null; // Lazily instantiated when needed

module.exports = function(params, callback) {
let directory;

Expand Down
8 changes: 7 additions & 1 deletion src/resolve-rc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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));
};

0 comments on commit c1f43cb

Please sign in to comment.