Skip to content

fix(stats): pass maxEntries to cache.set to enable LRU eviction - #39

Merged
m9tzin merged 1 commit into
mainfrom
fix/stats-cache-eviction
May 14, 2026
Merged

fix(stats): pass maxEntries to cache.set to enable LRU eviction#39
m9tzin merged 1 commit into
mainfrom
fix/stats-cache-eviction

Conversation

@m9tzin

@m9tzin m9tzin commented May 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • src/routes/stats.js chamava cache.set(key, data) sem o argumento maxEntries. Dentro de evictLruIfNeeded, a comparação this.store.size < undefined resolve para false (NaN), então a função sempre eviccionava a entrada mais antiga em cada cache miss, ao invés de pular a eviction quando abaixo do limite.
  • Efeito prático: cada miss em /stats derrubava silenciosamente uma entrada de /elo ou /streak do cache compartilhado, anulando o budget de maxEntries=200.
  • As outras rotas (elo.js:62, streak.js:62) já passavam config.cache.maxEntries corretamente — esta mudança alinha stats.js com o mesmo padrão.

Test plan

  • npm start e bater /stats?player=<nick> algumas vezes
  • Verificar que requests subsequentes para o mesmo player retornam do cache (hit) dentro do statsTtl (3 min)
  • Verificar que entradas de /elo e /streak não são mais evictadas em cada chamada de /stats
  • Não há mudança de comportamento quando o cache tem menos de 200 entradas (caso comum em produção)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Enhanced stats caching configuration for improved memory management efficiency.

Review Change Stack

The /stats route was calling cache.set(key, data) without the
maxEntries argument. Inside evictLruIfNeeded, the comparison
`this.store.size < undefined` evaluates to false (NaN), so the
function always evicted the oldest entry on every cache miss
instead of skipping eviction when below the limit. This silently
displaced /elo and /streak entries from the shared cache, defeating
the maxEntries=200 budget.

Other routes (elo.js, streak.js) already pass config.cache.maxEntries.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The /stats route now enforces cache size limits by passing config.cache.maxEntries as a third argument to cache.set(). This adds control over how many cached stats entries are retained.

Changes

Stats Cache Size Limit

Layer / File(s) Summary
Stats cache size limit
src/routes/stats.js
The cache write for computed formattedStats now includes config.cache.maxEntries to enforce bounded cache storage instead of unlimited entries.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

Poem

A rabbit bounces with cache control cheer, 🐰
One parameter passed to keep limits clear,
No unbounded entries in memory's keep,
Just stats in their boundaries, tidy and deep! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: passing maxEntries to cache.set to enable LRU eviction in the stats route, which directly aligns with the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/stats-cache-eviction

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@m9tzin
m9tzin merged commit 6bec528 into main May 14, 2026
7 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.

1 participant