mirror of
https://github.com/zhigang1992/deployd.git
synced 2026-05-13 12:37:17 +08:00
Merge branch '0.7' into 0.7-feature/module-dashboard
This commit is contained in:
@@ -16,10 +16,20 @@ var fs = require('fs')
|
||||
, loadModules = require('./module-loader')
|
||||
, qcall = require('./util/qcall');
|
||||
|
||||
var CACHE_EXPIRE_TIME_DEV = 2000
|
||||
, CACHE_EXPIRE_TIME_PROD = 1000*60*60; // hour
|
||||
|
||||
var __configCache = null
|
||||
, __cacheExpiration = 0;
|
||||
|
||||
module.exports.invalidateCache = function() {
|
||||
__configCache = null;
|
||||
__cacheExpiration = 0;
|
||||
};
|
||||
|
||||
module.exports.loadConfig = function(basepath, server, fn) {
|
||||
if (server.__configCache) {
|
||||
return fn(null, server.__configCache);
|
||||
if (__configCache && Date.now() < __cacheExpiration) {
|
||||
return fn(null, __configCache);
|
||||
}
|
||||
|
||||
var allModulesQ = q.nfcall(loadModules, basepath);
|
||||
@@ -88,8 +98,11 @@ module.exports.loadConfig = function(basepath, server, fn) {
|
||||
resourceTypes: resourceTypes
|
||||
};
|
||||
}).then(function(result) {
|
||||
if (server.options && server.options.env !== 'development') {
|
||||
server.__configCache = result;
|
||||
__configCache = result;
|
||||
if (server.options && server.options.env === 'development') {
|
||||
__cacheExpiration = Date.now() + CACHE_EXPIRE_TIME_DEV;
|
||||
} else {
|
||||
__cacheExpiration = Date.now + CACHE_EXPIRE_TIME_PROD;
|
||||
}
|
||||
fn(null, result);
|
||||
}, function(err) {
|
||||
|
||||
@@ -3,6 +3,7 @@ var fs = require('fs')
|
||||
, util = require('util')
|
||||
, wrench = require('wrench')
|
||||
, Resource = require('../resource')
|
||||
, invalidateCache = require('../config-loader')
|
||||
, debug = require('debug')('internal-resources')
|
||||
, path = require('path')
|
||||
, uuid = require('../util/uuid')
|
||||
@@ -76,8 +77,7 @@ InternalResources.prototype.handle = function(ctx, next) {
|
||||
}
|
||||
|
||||
if(ctx.req.method != 'GET' && ctx.server) {
|
||||
// clear cache
|
||||
delete ctx.server.__configCache;
|
||||
invalidateCache();
|
||||
}
|
||||
|
||||
switch (ctx.req.method) {
|
||||
|
||||
Reference in New Issue
Block a user