Skip to content

feat: add Redis caching for bounty listings (#128)#145

Open
TeapoyY wants to merge 1 commit intodevasignhq:mainfrom
TeapoyY:fix-issue-128-redis-caching-bounty-listings
Open

feat: add Redis caching for bounty listings (#128)#145
TeapoyY wants to merge 1 commit intodevasignhq:mainfrom
TeapoyY:fix-issue-128-redis-caching-bounty-listings

Conversation

@TeapoyY
Copy link
Copy Markdown

@TeapoyY TeapoyY commented Apr 5, 2026

Description

Fixes issue #128: Redis caching for the bounty listings.

Added Redis caching to the GET /api/bounties endpoint to improve performance for frequently-accessed bounty listings.

Changes

New dependency

  • Added ioredis ^5.6.1 to @devasign/api package

New service: packages/api/src/services/redis.ts

  • getRedisClient() - Lazy singleton Redis client using REDIS_URL env var
  • getCached<T>(key) - Get and parse JSON from Redis, returns null if Redis unavailable
  • setCache(key, value, ttlSeconds) - Set a JSON value with TTL
  • deleteCachePattern(pattern) - Scan and delete all keys matching a pattern (non-blocking)

Cache implementation in GET /api/bounties

  • Cache key is built deterministically from query params (tech_stack, amount_min, amount_max, difficulty, status, limit)
  • First page (no cursor) results are cached for 30 seconds (BOUNTY_LIST_CACHE_TTL)
  • Subsequent pages (with cursor) are not cached to keep pagination consistent
  • Cache is automatically invalidated when a bounty is updated or completed

Cache invalidation

  • PATCH /api/bounties/:id - Invalidates all bounty:list:* keys
  • POST /api/bounties/:id/complete - Invalidates all bounty:list:* keys

Testing

  1. Start Redis via docker-compose up redis
  2. Ensure REDIS_URL=redis://localhost:6379 in .env
  3. Request GET /api/bounties - first request hits DB, second request should be served from Redis cache
  4. Update a bounty - next listing request should hit DB again (cache invalidated)

Closes #128

- Added ioredis dependency for Redis support
- Created services/redis.ts with getCached, setCache, and deleteCachePattern helpers
- Added Redis caching to GET /api/bounties listing endpoint with 30s TTL
- Added cache invalidation on bounty update and complete actions
- Cache key is deterministic based on query params for consistent hits
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 for bounty listings and recommendations

1 participant