Closed CntChen closed 6 years ago
@CntChen
Caches the assets on initialization - you need to restart the process to update the assets.(can turn off with options.preload = false)
You can set [option. dynamic = true , option. preload = false ] to solve dynamic situation .
But there too many subdirectories to add xxx/index.html into options.files
How about write a method to generate cache object ...
files: {
'/sw.goods.js': {
path: path.join(appInfo.baseDir, 'app/public/sw.goods.js'),
cacheControl: 'no-cache, max-age=0, no-store, must-revalidate',
maxAge: 0,
mime: 'application/javascript',
type: 'application/javascript',
mtime: new Date(),
+ length: fs.statSync(path.join(appInfo.baseDir, 'app/public/sw.goods.js')).size,
},
},
Thx for response!
options.preload=false
, don't load files into memory (JS object) when static-cache
init.
options.dynamic=true
during http request, if files not in memory, load file from disk, and add file into cache using options.files
strategies.
Generating cache object can deal with too many subdirectories
, but cache object is genrated before static-cache
init.
My case, when static-cache
is running, the subdirectories inside public
will increase.
when static-cache
init:
./public
├── A
├── index.html
└── index.js
when static-cache
running:
./public
├── A
│ ├── index.html
│ └── index.js
├── B
│ ├── index.html
│ └── index.js
└── ...
├── index.html
└── index.js
In this case, options.files
include public/A/index.html
but not public/B/index.html
.
During a http request, use options.ignorefiles
to control cache for special files may work.
I got it . Let the dynamic files in other folder such as cache/
and config some routers ?
app.get('/cache/B/index.html',controller.dynamic)
Yes, there are other ways to deal with my case, but the way will beyond the range of static-cache
.
generally speaking, static-cache
is use for directory/files which are static.
In a case like below:
directory structure:
I want ignore cache for file
index.html
in each subdirectory inpublic
. Because eachindex.html
is generated by SSR in my case. But there too many subdirectories to addxxx/index.html
intooptions.files
, and some subdirectories name are generated dynamically afterstatic-cache
init.research
static-cache
usepathname
as cache key,options.files
object can't not use a RegExp as key.question
can
static-cache
add an option calledignorefiles
or another name, which type is one of RegExp/RegExpArray/filename/filenameArray, and ignore cache for files which matchignorefiles
.generally speaking,
static-cache
is use for directory/files which are static. So I am not sure this idea is worth and useful.@dead-horse @fengmk2 @Gorden-Wang