Express View Cache Clean
Express enables view template compilation caching in production (when NODE_ENV
is production
) which can improve performance. express-view-cache-clean
can watch view file changes to clean relative caches.
NOTICE: only supported ejs template!!
Installation
yarn add express-view-cache-clean
or
npm i express-view-cache-clean --save
Example
const express = const expressViewCacheClean = const app =
Options
Clean Up Options
-
app: Express
(required) -
viewPath: String
(required) -
rules: Object | Array<String> | Array<Object>
(required)Multiple
rules
configuration formats:// when filename includes 'page' view file changes, it will clean name includes 'page/home' cacherules:'page/home': 'page/home'rules:'page/home''page/category'rules:filename: 'page/home'cache: 'page/home'Multiple
filename
configuration formats:// Stringfilename: 'page/home'// Function{return filename}// Regexfilename: /page\/home/Multiple
cache
configuration formats:// Stringcache: 'page/home'// Function{return viewname}// RegExpcache: /page\/home/// Array<String | Function | RegExp>cache:'page/home'{return viewname}cache: /page\/other/
Watch Options
The usage and options are compatible with fs.watch.
-
persistent: Boolean
(default true) -
recursive: Boolean
(default false) -
encoding: String
(default 'utf8') -
filter: RegExp | Function
(default null)Return that matches the filter expression.
// filter with regular expressionfilter: /\.json$/// filter with custom function!/node_modules/ -
delay: Number
(in ms, default 200)Delay time of the callback function.
// log after 5 secondsdelay: 5000 -
events: Array<String>
(default ['update'])Watch file events,
update
orremove
.// only watch file update eventevents: 'update'// watch file all eventevents: 'update' 'remove'