The Problems Cache uses the Decorator Pattern to intercept and cache the heavy MongoDB queries executed by the repositories.
File Location: api/src/cache/problems/
Because coding problems rarely change, they are aggressively cached.
findMany: Caches the paginated grid view.- Key:
problems:list:{limit}:{offset}:{filters} - TTL: 300 seconds (5 minutes). This is short enough that new problems appear quickly, but long enough to absorb traffic spikes.
- Key:
findBySlug: Caches the individual problem details.- Key:
problem:slug:{slug} - TTL: 86400 seconds (24 hours). The details of a problem almost never change.
- Key:
- Invalidation: When
createorupdateis called, the cache immediately callsredis.del()on the specific slug key and wildcard flushes theproblems:list:*keys so the grid instantly updates.
Test cases are fetched constantly by the backend Judge worker during evaluation.
findAllByProblem: Caches both public and hidden test cases together.- Key:
problem-tests:{problemId} - TTL: 86400 seconds (24 hours).
- Key:
- Worker Optimization: By caching this, the Judge worker (
SubmissionEvaluator) can fetch all 100 hidden test cases from Redis memory in milliseconds rather than hitting MongoDB on every code submission!