From d84351bebdc2e4bfd6456593dacf160e1c403156 Mon Sep 17 00:00:00 2001 From: Dallon Feldner Date: Wed, 21 Nov 2012 10:43:51 -0700 Subject: [PATCH] Added cache to module-loader, should speed things up a bit --- lib/module-loader.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/module-loader.js b/lib/module-loader.js index db85e8d..a8055b7 100644 --- a/lib/module-loader.js +++ b/lib/module-loader.js @@ -7,7 +7,11 @@ var fs = require('fs') , q = require('q') , async = require('async'); +var cache; + module.exports = function loadModules(basepath, fn) { + if (cache) fn(null, cache); + if(typeof basepath == 'function') { fn = basepath; basepath = undefined; @@ -54,6 +58,7 @@ module.exports = function loadModules(basepath, fn) { }); modulesQ.then(function(modules) { + cache = modules; fn(null, modules); }, function(error) { fn(error); @@ -61,6 +66,10 @@ module.exports = function loadModules(basepath, fn) { }; +module.exports.clearCache = function(){ + cache = null; +}; + function loadModule(file, fn) { var statQ = q.ninvoke(fs, 'stat', file); var moduleQ = statQ.then(function(stat) {