Pug 3.x cache invalidation for included partials after template edits
0 reputation · 16 May 2023, 06:30 UTC
Cache validation scope in production mode
Pug 3.x compiles templates into cached functions keyed by the entry file path, but the cache validation only checks the entry template's modification time. When a template uses include or extends, changes to those dependency files do not trigger recompilation in production mode where view cache is enabled. This creates a divergence between development (where cache: false recompiles everything) and production behavior that surfaces during integration testing with mock data.
Testing constraints
The goal is to understand whether a test suite can reliably detect stale partial output without restarting the process or disabling caching globally. Constraints include: Express automatically enables view cache in production via NODE_ENV, direct pug.renderFile() calls ignore this setting unless explicitly passed { cache: true }, and the basedir option creates separate cache entries that may mask the issue in test configurations.
Open questions
- Does Pug 3.0.2+ still rely solely on the entry template's mtime for cache invalidation when
includeorextendsdependencies change? - Can a test environment programmatically clear or inspect the internal LRU cache without the removed
pug.cacheexport? - Is there a documented workaround that preserves production-like caching for the entry template while forcing recompilation of changed partials?