Skip to content

feat: add per-endpoint cache TTL configuration via env vars (#282)#427

Merged
Sulex45 merged 1 commit into
stellarkit-lab-devtools:mainfrom
Ebenezer199914:feat/per-endpoint-cache-ttl-282
Jun 29, 2026
Merged

feat: add per-endpoint cache TTL configuration via env vars (#282)#427
Sulex45 merged 1 commit into
stellarkit-lab-devtools:mainfrom
Ebenezer199914:feat/per-endpoint-cache-ttl-282

Conversation

@Ebenezer199914

Copy link
Copy Markdown
Contributor

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_MS env var controlling the fee-estimate endpoint.

Changes

New file: src/config/cacheConfig.js

Centralised TTL config module. Reads six dedicated env vars (in ms), converts to seconds, and exports a plain cacheTTL object used by all route handlers.

Env var Endpoint Default
CACHE_TTL_NETWORK_STATUS_MS /network-status 5 000 ms
CACHE_TTL_FEE_ESTIMATE_MS /fee-estimate + surge-status 5 000 ms
CACHE_TTL_BASE_FEE_MS /network/base-fee 5 000 ms
CACHE_TTL_VALIDATORS_MS /network/validators 300 000 ms
CACHE_TTL_ASSET_MS /asset/:code/:issuer 30 000 ms
CACHE_TTL_ASSET_PRICE_MS asset price endpoint 5 000 ms

The legacy CACHE_TTL_MS variable is still honoured as a global fallback — existing deployments are unaffected.

Updated routes

  • src/routes/networkStatus.js — removed hardcoded CACHE_TTL = 5
  • src/routes/feeEstimate.js — removed inline env-var derivation
  • src/routes/network.js — removed VALIDATORS_CACHE_TTL and BASE_FEE_CACHE_TTL constants
  • src/routes/asset.js — removed hardcoded 30 and CACHE_TTL_ASSET_PRICE constant

.env.example

Added all six per-endpoint variables with inline documentation alongside the existing CACHE_TTL_MS global fallback.

Tests: tests/cacheConfig.test.js

20 unit tests covering:

  • Default values for all 6 keys
  • Per-endpoint env var overrides
  • Global CACHE_TTL_MS fallback precedence
  • Edge cases: NaN, zero, negative, large values

Testing

PASS tests/cacheConfig.test.js        (20/20)
PASS tests/cache.service.test.js
PASS tests/cache.integration.test.js
PASS tests/feeEstimate.test.js
PASS tests/network.base-fee.test.js
PASS tests/network.validators.test.js
PASS tests/asset.test.js

Tests: 45 passed, 45 total

…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).
@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@Sulex45 Sulex45 merged commit 36f5fc0 into stellarkit-lab-devtools:main Jun 29, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance & Caching | Add per-endpoint cache TTL configuration via environment variables

2 participants