Skip to content

feat(sep1): add Redis caching strategy for SEP-1 info responses#480

Merged
Ceejaytech25 merged 1 commit into
ceejaylaboratory:mainfrom
Damola09:feat/sep1-redis-cache-368
May 29, 2026
Merged

feat(sep1): add Redis caching strategy for SEP-1 info responses#480
Ceejaytech25 merged 1 commit into
ceejaylaboratory:mainfrom
Damola09:feat/sep1-redis-cache-368

Conversation

@Damola09
Copy link
Copy Markdown
Contributor

Summary

Adds a Redis-backed cache for the SEP-1 anchor info endpoint as specified in issue #368.

  • New Sep1InfoCacheService with stale-while-revalidate pattern (TTL: 5 min, grace: 60 s)
  • getOrCompute(computeFn): returns fresh cached value, serves stale and triggers background refresh, or recomputes on full miss
  • get(), isStale(), set(), invalidate() methods for fine-grained cache control
  • All Redis errors are swallowed - endpoint always falls back to computing fresh
  • Extracts buildStellarInfo() from getInfo for clean cache-aside usage
  • getInfo is now async returning Promise
  • 18 unit tests with fake Redis client covering all cache states and error paths

Test plan

  • Cold miss: calls computeFn and writes to Redis
  • Fresh hit: returns cached value without calling computeFn
  • Stale-while-revalidate: returns stale value immediately, schedules background refresh
  • Fully expired: recomputes synchronously
  • Redis get/set/del failures: never throws, always falls back
  • set() writes with extended TTL (TTL + grace)
  • invalidate() deletes the cache key

Fixes #368

- Add src/services/sep1-info-cache.service.ts:
    - TTL: 5 min, stale-while-revalidate grace: 60 s
    - getOrCompute(): cache-aside with background refresh on stale hit
    - Graceful Redis failure: swallows errors, always falls back to computeFn
    - invalidate(): explicit cache bust for config/asset changes
    - Static accessors (cacheKey, ttlSeconds, staleGraceSeconds) for tests
- Refactor info.controller.ts:
    - Extract buildStellarInfo() for reuse by cache compute function
    - Make getInfo() async; serve response via sep1InfoCache.getOrCompute()
    - Redis unavailability is non-fatal; endpoint always returns a response
- Update info.controller.test.ts: await async getInfo() in all existing tests
- Add sep1-info-cache.service.test.ts: 18 unit tests covering cold miss,
  fresh hit, stale-while-revalidate, full expiry, Redis failures (get/set/del),
  TTL write, and invalidation

Fixes ceejaylaboratory#368
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 29, 2026

@Damola09 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

@Ceejaytech25
Copy link
Copy Markdown
Contributor

LGTM!

@Ceejaytech25 Ceejaytech25 merged commit 5d7e49b into ceejaylaboratory:main May 29, 2026
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.

[Backend] Redis Cache Strategy for SEP-1 Info

2 participants