Skip to content

feat(cache): implement Redis caching layer for Horizon ledger queries - #87

Merged
SharifIbrahimDev merged 1 commit into
sharif-stellar-tools:masterfrom
ravimahatonp:feat/redis-caching-layer-73
Oct 13, 2026
Merged

SharifIbrahimDev merged 1 commit into
sharif-stellar-tools:masterfrom
ravimahatonp:feat/redis-caching-layer-73

Conversation

@ravimahatonp

Copy link
Copy Markdown
Contributor

Summary of Changes

This PR implements a robust, dependency-free Redis caching layer to cache frequently accessed historical ledgers and Horizon queries, resolving redundant network calls and rate-limiting bottlenecks.

Key Features:

  • Native RESP Protocol Client (NativeRedisClient): Implemented lightweight Redis RESP protocol parser over Node's native net socket module with zero external npm dependencies.
  • Graceful In-Memory Fallback: Seamlessly falls back to an in-memory TTL cache when Redis is unavailable, ensuring offline resilience and predictable testing.
  • Ledger-Specific Cache Helpers:
    • setLedger(ledger): Stores ledger by sequence and hash with configurable TTL (default 24h for immutable ledgers).
    • getLedger(sequenceOrHash): Fast indexed lookup.
    • getOrFetchLedger(sequence, fetchFn): Read-through cache helper that queries Horizon only on cache misses.
  • Runtime Metrics & Hit Ratio: Tracks total hits, misses, hit ratio, active backend, and connection status.
  • Unit & Integration Tests: Added 14 unit and integration tests in tests/cache/redisCache.test.ts (100% passing).
  • Usage Example Demo: Added executable example in examples/redis-cache-demo.ts.

Closes #73

@SharifIbrahimDev
SharifIbrahimDev merged commit 39b58fc into sharif-stellar-tools:master Oct 13, 2026
1 check failed
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.

Implement caching layer using Redis to optimize repeated queries

2 participants