修改缓存方式为文件缓存

master
宇天 2020-04-19 11:27:07 +08:00
parent ba25d33f99
commit f77109be52
2 changed files with 8 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/** /**
* nodeJS 模板引擎(依赖doJS框架) * nodeJS 模板引擎
* @authors yutent (yutent@doui.cc) * @authors yutent (yutent@doui.cc)
* @date 2015-12-28 13:57:12 * @date 2015-12-28 13:57:12
* *
@ -10,6 +10,7 @@ require('es.shim')
const Tool = require('./lib/tool') const Tool = require('./lib/tool')
const path = require('path') const path = require('path')
const fs = require('iofs')
function hash(str) { function hash(str) {
return Buffer.from(str).toString('hex') return Buffer.from(str).toString('hex')
@ -76,20 +77,22 @@ class Smarty {
key = hash(tpl) key = hash(tpl)
if (this.__CACHE__[key]) { if (this.__CACHE__[key]) {
return Promise.resolve(this.__CACHE__[key]) return Promise.resolve(fs.cat(path.resolve('./cache/', key)))
} }
cache = this.tool.__readFile__(tpl, noParse) cache = this.tool.__readFile__(tpl, noParse)
if (noParse) { if (noParse) {
this.__CACHE__[key] = cache this.__CACHE__[key] = true
fs.echo(cache, path.resolve('./cache/', key))
return Promise.resolve(cache) return Promise.resolve(cache)
} }
try { try {
cache = this.tool.parse(cache, this.__DATA__) cache = this.tool.parse(cache, this.__DATA__)
if (this.opt.cache) { if (this.opt.cache) {
this.__CACHE__[key] = cache this.__CACHE__[key] = true
fs.echo(cache, path.resolve('./cache/', key))
} }
return Promise.resolve(cache) return Promise.resolve(cache)
} catch (err) { } catch (err) {

View File

@ -1,6 +1,6 @@
{ {
"name": "smartyx", "name": "smartyx",
"version": "1.3.1", "version": "1.4.0",
"description": "nodeJS模板引擎理念源自于PHP的smarty模板引擎", "description": "nodeJS模板引擎理念源自于PHP的smarty模板引擎",
"keywords": ["fivejs", "smarty", "template", "ejs", "jade"], "keywords": ["fivejs", "smarty", "template", "ejs", "jade"],
"author": "宇天 <yutent@doui.cc>", "author": "宇天 <yutent@doui.cc>",