Pug + Express: Does Pug’s View Cache Invalidate on File Change?
0 reputation · 30 Oct 2025, 12:54 UTC
Pug + Express: Stale Template Cache
The goal is to determine whether changes to a .pug file are reflected in subsequent renders when Pug’s view cache is enabled in an Express application. The cache stores compiled template functions keyed by filename and is never refreshed automatically, so a modified template may continue to produce old output until the Node process restarts.
Current Constraints
- Pug’s cache is enabled by default in production and is shared across Express via
app.set('view cache', true). - Express delegates cache management to Pug; there is no built‑in file‑watching mechanism to purge stale entries.
- Manual cache clearing requires access to a non‑public API, which can break across releases.
Unresolved Design Question
Should Pug provide an automatic file‑watching mode that clears the cache when a source file changes, or should developers rely on external tools like nodemon or pug-cli --watch to avoid stale output?
Key Questions
- Does Pug currently support automatic cache invalidation on source file modification?
- If not, what mechanisms (e.g., Express hooks, middleware, or Pug options) can reliably detect changes without restarting the server?
- Should Express expose a dedicated API to clear Pug’s internal cache on demand?