Skip to content
This repository was archived by the owner on May 17, 2026. It is now read-only.

Repository files navigation

This repository has been migrated. For ongoing updates, please see https://github.com/thinkjs/thinkjs/tree/master/packages/think-html-cache.

think-html-cache

html-cache middleware for ThinkJS 2.0

Install

npm install think-html-cache

How to use

register middleware

create file is not exist, src/common/bootstrap/middleware.js

importhtmlCachefrom'think-html-cache';think.middleware('html_cache',htmlCache);

hook config

src/common/config/hook.js

exportdefault{logic_before: ['prepend','html_cache'],view_after: ['append','html_cache']}

html_cache config

create file is not exist src/common/config/html_cache.js:

exportdefault{on: true,//use html_cachetype: 'base',//cache content store typetimeout: 0,callback: function(key){returnthink.md5(key);},rules: {'home/index/index': ['index_{page}',timeout,callback],'index/detail': ['index_{id}',timeout,callback]},//adapter configadapter: {file: {path: think.getPath('common','runtime')+'/html_cache'//when type is file, set cache path}}}

type

cache content store type, support base & file.

timeout

expire time, if value is 0, only expired when template is updated.

callback

encrypt cache key, such as:

function(key){returnthink.md5(key);}

rules

cache rules, key is [module]/[controller]/[action].

can get paramters in rule:

'index_{page}' // get page paramter from GET
'index_{:module}' // get module value
'index_{:controller}' //get controller value
'index_{:action}' //get action value
'index_{cookie.xxx}' //get value from cookie

LICENSE

MIT

About

html-cache middleware for ThinkJS 2.0

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages