mirror of
https://github.com/zhigang1992/deployd.git
synced 2026-05-13 12:37:17 +08:00
Added cache to module-loader, should speed things up a bit
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user