Make module loader TTL bounded by default#1345
Open
Zetazzz wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
createModuleLoaderso cache hits do not refresh TTL by default.updateAgeOnGetoption for loaders that intentionally need sliding TTL / idle-expiry semantics.databaseId/databaseId:apiIdcache keys.Why
createModuleLoaderis used for runtime settings that may change while the server process is still running. If cache hits refresh the TTL by default, a hot setting effectively becomes a sliding cache entry: every read pushes the expiration window forward. Under steady traffic, that can keep a stale value alive far beyond the configuredttlMs, and in practice it may not be reloaded from the database until traffic pauses or the process invalidates the key explicitly.The safer default is to treat
ttlMsas a bounded staleness window: once a value is cached, it can be reused until that original window expires, but reads do not extend the window. This makes freshness easier to reason about for loader-backed settings.Loaders that truly want read-time TTL refresh can still opt in with
updateAgeOnGet: true. Requiring that option to be explicit is intentional: sliding TTL is a different freshness contract, and a maintainer adding it is very likely making a deliberate trade-off for an idle-expiry cache rather than accidentally inheriting it as the global default.Example
Suppose
authSettingsLoadercaches auth/OAuth runtime settings with a 5 minute TTL, and login traffic reads those settings continuously.With the old default (
updateAgeOnGet: true):With the new default (
updateAgeOnGet: false):That keeps the configured TTL as the maximum normal staleness window for loader-backed settings, while preserving an explicit escape hatch for loaders that intentionally want sliding idle-expiry behavior.
Testing
../../node_modules/.bin/jest --config jest.config.js src/loaders/__tests__/create-loader.test.ts --runInBand../../node_modules/.bin/jest --config jest.config.js --runInBand../../node_modules/.bin/makage build --dev