Skip to content

fix(rates): instantiate RateService singleton in AppState to enable cache (#36) - #69

Open
ghzhost wants to merge 1 commit into
StellarSend:mainfrom
ghzhost:fix/rate-service-singleton-cache-36
Open

fix(rates): instantiate RateService singleton in AppState to enable cache (#36)#69
ghzhost wants to merge 1 commit into
StellarSend:mainfrom
ghzhost:fix/rate-service-singleton-cache-36

Conversation

@ghzhost

@ghzhost ghzhost commented Sep 2, 2026

Copy link
Copy Markdown

Overview

Fixes #36 by instantiating RateService once at startup and storing it in AppState, allowing GET /api/rates to properly share and leverage the in-memory TTL cache across requests.

Changes

  1. AppState Singleton: Added pub rate_service: services::rate::RateService to AppState and initialized it once during startup in src/main.rs using the configured horizon_url and rate_cache_ttl_secs.
  2. Route Handler: Updated src/routes/rates.rs to call state.rate_service.fetch_rate(...) directly instead of allocating a fresh RateService (with a discarded empty cache) on every request.
  3. Unit Tests: Added wiremock-backed tests in src/services/rate.rs verifying that cache hits occur within the configured TTL window without repeating outbound calls to Horizon.

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.

GET /api/rates builds a brand-new RateService (and empty cache) on every request — the RATE_CACHE_TTL_SECS cache is dead code

1 participant