feat: add per-endpoint cache TTL configuration via env vars (#282)#427
Merged
Sulex45 merged 1 commit intoJun 29, 2026
Conversation
…devtools#282) - Add src/config/cacheConfig.js — centralised TTL config module that reads CACHE_TTL_NETWORK_STATUS_MS, CACHE_TTL_FEE_ESTIMATE_MS, CACHE_TTL_BASE_FEE_MS, CACHE_TTL_VALIDATORS_MS, CACHE_TTL_ASSET_MS, CACHE_TTL_ASSET_PRICE_MS from env (all in ms, converted to seconds). Falls back to per-endpoint sensible defaults; respects legacy CACHE_TTL_MS as a global fallback so existing deployments are unaffected. - Update networkStatus.js, feeEstimate.js, network.js, asset.js to import cacheTTL from cacheConfig and replace all hardcoded TTL values. - Update .env.example with all six new per-endpoint variables alongside the existing CACHE_TTL_MS global fallback, with inline comments. - Add tests/cacheConfig.test.js: 20 tests covering default values, per-endpoint overrides, global fallback precedence, and edge cases (NaN, zero, negative, large values).
|
@Ebenezer199914 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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
Resolves #282 — Performance & Caching | Add per-endpoint cache TTL configuration via environment variables.
Previously, all cache TTLs were hardcoded constants scattered across individual route files, with only a single
CACHE_TTL_MSenv var controlling the fee-estimate endpoint.Changes
New file:
src/config/cacheConfig.jsCentralised TTL config module. Reads six dedicated env vars (in ms), converts to seconds, and exports a plain
cacheTTLobject used by all route handlers.CACHE_TTL_NETWORK_STATUS_MS/network-statusCACHE_TTL_FEE_ESTIMATE_MS/fee-estimate+ surge-statusCACHE_TTL_BASE_FEE_MS/network/base-feeCACHE_TTL_VALIDATORS_MS/network/validatorsCACHE_TTL_ASSET_MS/asset/:code/:issuerCACHE_TTL_ASSET_PRICE_MSThe legacy
CACHE_TTL_MSvariable is still honoured as a global fallback — existing deployments are unaffected.Updated routes
src/routes/networkStatus.js— removed hardcodedCACHE_TTL = 5src/routes/feeEstimate.js— removed inline env-var derivationsrc/routes/network.js— removedVALIDATORS_CACHE_TTLandBASE_FEE_CACHE_TTLconstantssrc/routes/asset.js— removed hardcoded30andCACHE_TTL_ASSET_PRICEconstant.env.exampleAdded all six per-endpoint variables with inline documentation alongside the existing
CACHE_TTL_MSglobal fallback.Tests:
tests/cacheConfig.test.js20 unit tests covering:
CACHE_TTL_MSfallback precedenceTesting