This commit is contained in:
welefen 2014-05-05 10:10:19 +08:00
parent a2009c3464
commit 19e98e0b1a
5 changed files with 9 additions and 6 deletions

View File

@ -85,6 +85,7 @@ module.exports = {
html_cache_on: false, //HTML静态缓存
html_cache_timeout: 3600, //缓存时间,单位为秒
html_cache_rules: {}, //缓存规则
html_cache_path: CACHE_PATH + "/html",
html_cache_file_callback: undefined, //生成缓存文件的回调函数
html_cache_file_suffix: ".html", //缓存文件后缀名

View File

@ -12,6 +12,7 @@ module.exports = Behavior(function(){
'html_cache_on': false, //是否开启缓存
'html_cache_timeout': 3600, //缓存时间
'html_cache_rules': {}, //缓存规则
'html_cache_path': "",
'html_cache_file_callback': undefined, //生成缓存文件的回调函数
'html_cache_file_suffix': ".html", //缓存文件扩展名
},
@ -36,7 +37,7 @@ module.exports = Behavior(function(){
*/
responseCacheContent: function(){
var http = this.http;
var fileStream = fs.createReadStream(HTML_PATH + "/" + http.html_filename);
var fileStream = fs.createReadStream(this.options.html_cache_path + "/" + http.html_filename);
http.setHeader("Content-Type", "text/html");
http.sendTime("Exec-Time");
fileStream.pipe(http.res);
@ -114,7 +115,7 @@ module.exports = Behavior(function(){
* @return {[type]} [description]
*/
checkCacheTime: function(cacheTime){
var cacheFile = HTML_PATH + "/" + this.http.html_filename;
var cacheFile = this.options.html_cache_path + "/" + this.http.html_filename;
if (!isFile(cacheFile)) {
return false;
}

View File

@ -14,14 +14,15 @@ module.exports = Behavior(function(){
"use strict";
return {
options: {
"html_cache_on": false //是否开启缓存
"html_cache_on": false, //是否开启缓存
"html_cache_path": ""
},
run: function(content){
if (!this.options.html_cache_on || !this.http.html_filename) {
return content;
}
this.recordViewFile();
var file = HTML_PATH + "/" + this.http.html_filename;
var file = this.options.html_cache_path + "/" + this.http.html_filename;
mkdir(path.dirname(file));
//异步方式写入缓存
fs.writeFile(file, content);

View File

@ -49,7 +49,7 @@ module.exports = {
CONF_PATH: APP_PATH + "/Conf",
LANG_PATH: APP_PATH + "/Lang",
VIEW_PATH: APP_PATH + "/View",
HTML_PATH: RUNTIME_PATH + "/Html",
//HTML_PATH: RUNTIME_PATH + "/Html",
LOG_PATH: RUNTIME_PATH + "/Log",
TEMP_PATH: RUNTIME_PATH + "/Temp",
DATA_PATH: RUNTIME_PATH + "/Data",

View File

@ -1,7 +1,7 @@
{
"name": "thinkjs",
"description": "thinkphp web framework for nodejs",
"version": "0.5.8",
"version": "0.5.9",
"author": {
"name": "welefen",
"email": "welefen@gmail.com"