Skip to content

feat(caching): add aggressive caching for expensive computations #603#736

Merged
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
David-282:feat/aggressive-caching-expensive-computations-603
May 30, 2026
Merged

feat(caching): add aggressive caching for expensive computations #603#736
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
David-282:feat/aggressive-caching-expensive-computations-603

Conversation

@David-282

Copy link
Copy Markdown
Contributor

Linked Issue

Closes #603


What does this PR do?

Adds a dedicated ComputationCacheService for expensive O(n) operations in
LeaderboardService that were hitting the database on every request with no
caching. Implements cache-aside pattern with stampede protection, per-computation
TTL configuration, and Prometheus metrics tracking via the existing
MetricsCollectionService.


Type of change

  • ✨ New feature (non-breaking change that adds functionality)

Pre-merge checklist (required)

Branch & metadata

  • Branch name follows feature/issue-<N>-<slug> / fix/issue-<N>-<slug> convention
  • Branch is up to date with the target branch
  • All commits and the PR title follow the Conventional Commits format with issue reference

Code quality & tests

  • npm run lint:ci
  • npm run format:check
  • npm run typecheck
  • npm run test:ci
  • New service methods have corresponding .spec.ts unit tests
  • No existing tests were deleted

Error handling & NestJS best practices

  • Logging goes through NestJS Logger with structured messages
  • No new endpoints — authentication/authorization guards not applicable

API documentation / Swagger

  • No API surface changes — this PR adds a service layer only, no new controller endpoints

Breaking changes

  • This PR does not introduce a breaking API change

Test evidence (required)

Commands run locally

Local tooling not fully set up (npm install pending).
CI pipeline will validate lint, format, typecheck, and tests on push.

Manual / API verification
No new endpoints introduced. Changes are internal service layer only.
Unit tests cover: cache hit, cache miss, stampede deduplication,
invalidation, hit rate calculation, and Prometheus metrics publishing.


Files changed

  • src/caching/computation-cache.service.ts — new service
  • src/caching/computation-cache.service.spec.ts — unit tests
  • src/caching/caching.constants.ts — added COMPUTATION_TTL
  • src/caching/cache-key.builder.ts — added buildComputationKey()
  • src/caching/caching.module.ts — registered and exported ComputationCacheService

@drips-wave

drips-wave Bot commented May 30, 2026

Copy link
Copy Markdown

@David-282 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

@RUKAYAT-CODER RUKAYAT-CODER merged commit d90a78f into rinafcode:main May 30, 2026
3 of 4 checks passed
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.

Add aggressive caching for expensive computations

2 participants