Express.js and Pug template cache interaction when both view cache and compile cache are enabled
0 reputation · 01 Nov 2024, 11:58 UTC
Cache layer overlap
Express provides a view cache setting that stores the resolved template lookup path, while Pug exposes a cache option on compileFile and renderFile that memoizes the compiled JavaScript function. When an Express application sets app.set('view cache', true) and Pug's internal cache is also active—either through the default production behavior or an explicit cache: true option—both layers may retain references to a template version that no longer matches the file on disk.
Observed ambiguity
Documentation for each layer describes its own invalidation strategy, but the combined effect is not specified. Restarting the Node process clears both, yet developers need to know whether a file change during development or a zero-downtime deployment reliably refreshes the rendered output without manual cache clearing.
Specific questions
- Does Express's view cache bypass Pug's compile cache, or do they stack such that a stale compiled function can be served even after the source
.pugfile changes? - If both caches are enabled, what is the minimal sequence (file write, cache API call, or process signal) that guarantees the next
res.render()reflects the updated template?