diff options
-rw-r--r-- | lib/utils/read-json.js | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/utils/read-json.js b/lib/utils/read-json.js index 8b71971b2..974123655 100644 --- a/lib/utils/read-json.js +++ b/lib/utils/read-json.js @@ -5,10 +5,17 @@ readJson.processJson = processJson var fs = require("./graceful-fs") , semver = require("./semver") , path = require("path") - + , log = require("./log") + , cache = {} + , timers = {} function readJson (jsonFile, opts, cb) { if (typeof cb !== "function") cb = opts, opts = {} + if (cache.hasOwnProperty(jsonFile)) { + log.verbose(jsonFile, "from cache") + return cb(null, cache[jsonFile]) + } fs.readFile(path.join(path.dirname(jsonFile), "wscript"), function (er, data) { + opts.file = jsonFile if (er) opts.wscript = false else opts.wscript = data.toString().match(/(^|\n)def build\b/) && data.toString().match(/(^|\n)def configure\b/) @@ -122,6 +129,16 @@ function processObject (opts, cb) { return function (er, json) { json._id = json.name+"-"+json.version json = testEngine(json) json = parsePeople(json) + if (opts.file) { + log.verbose(opts.file, "caching") + cache[opts.file] = json + // just in case this is a long-running process... + clearTimeout(timers[opts.file]) + timers[opts.file] = setTimeout(function () { + delete cache[opts.file] + delete timers[opts.file] + }, 1000 * 60 * 60 * 24) + } if (cb) cb(null,json) return json }} |