Skip to content

[server] - Add Redis Caching Layer for Frequently Read Endpoints #76

Description

@dark-sarge

Location: server/src/utils/cache.ts

Description

High-traffic read endpoints such as GET /api/trades (marketplace listing) will be queried repeatedly by many users simultaneously. Without a caching layer, every request hits PostgreSQL, increasing latency and database load. A Redis-backed cache with TTL-based invalidation should be added for expensive read paths.

Acceptance Criteria

  • ioredis is added as a dependency and a shared Redis client is initialised from a REDIS_URL environment variable.
  • A cache.get<T>(key) and cache.set<T>(key, value, ttlSeconds) utility is created in server/src/utils/cache.ts.
  • GET /api/trades (marketplace listing) caches the full response for 30 seconds, keyed by the serialised query params.
  • Cache entries are invalidated when a new trade is created or an existing trade's status changes.
  • Cache reads are logged at debug level; cache misses are logged at info level with the key.
  • If Redis is unavailable the server falls back to direct database reads and logs a warn — it does not crash.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions