Skip to content

feat: cache GET /api/v1/stats endpoint data in Redis#1295

Open
Bellamzy wants to merge 1 commit into
Web3Novalabs:mainfrom
Bellamzy:feat/cache-stats-endpoint
Open

feat: cache GET /api/v1/stats endpoint data in Redis#1295
Bellamzy wants to merge 1 commit into
Web3Novalabs:mainfrom
Bellamzy:feat/cache-stats-endpoint

Conversation

@Bellamzy

Copy link
Copy Markdown

feat: cache GET /api/v1/stats endpoint data in Redis

Summary

Implements the cache-aside pattern for the GET /api/v1/stats endpoint to reduce repeated
database aggregation queries.

Changes

backend/src/redis_cache.rs

  • Added STATS_CACHE_TTL = 30 (30-second TTL)
  • Added STATS_CACHE_PATTERN = "stats:*" for bulk invalidation
  • Added stats_cache_key(category, status) — encodes filter params into a Redis key (e.g.
    stats:sports:active, stats:all:all)
  • Added invalidate_stats_cache() method
  • Added unit tests for key generation, uniqueness, TTL, and invalidation

backend/src/routes/v1.rs

  • get_stats: check Redis first → on hit return cached value; on miss query DB, cache result for
    30s, return
  • ingest_pool_created: invalidates stats cache on new pool (affects total_pools /
    total_value_locked)
  • ingest_prediction_placed: invalidates stats cache on new bet (affects total_bets /
    total_value_locked)
  • Added unit tests for the cache-aside flow

Behaviour

  • Stats are served from Redis for up to 30 seconds after the last write event
  • Cache is invalidated immediately when a pool is created or a prediction is placed, so stale
    data is bounded
  • Falls back gracefully to the database when Redis is unavailable (fail-open)
    closes feat(backend): cache statistics endpoint data in redis #1145

@vercel

vercel Bot commented Jun 28, 2026

Copy link
Copy Markdown

@Bellamzy is attempting to deploy a commit to the shola's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

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

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.

feat(backend): cache statistics endpoint data in redis

1 participant