Skip to content

Use LRU eviction for evaluation cache instead of FIFO#22

Open
jdcodes1 wants to merge 1 commit into
imbue-ai:mainfrom
jdcodes1:feat/lru-cache-eviction
Open

Use LRU eviction for evaluation cache instead of FIFO#22
jdcodes1 wants to merge 1 commit into
imbue-ai:mainfrom
jdcodes1:feat/lru-cache-eviction

Conversation

@jdcodes1

@jdcodes1 jdcodes1 commented Apr 12, 2026

Copy link
Copy Markdown

Summary

  • Converts the 500-item evaluation cache from FIFO to LRU eviction
  • On cache hit, deletes and re-inserts the entry to move it to the end of Map iteration order
  • Eviction still removes the first key — but now that's the least recently used entry, not the oldest

Problem: Trending/viral posts appear repeatedly in feeds. Under FIFO, a post seen 50 times gets evicted just because 500 other posts came after it, forcing a redundant LLM call next time the user scrolls past it.

Fix: 3 lines — delete + set on cache hit promotes the entry. JavaScript Map preserves insertion order, so this is a clean O(1) LRU without any new data structures.

Test plan

  • Added test verifying recently accessed entries survive eviction while true LRU entries are evicted
  • All 200 existing tests pass
  • No changes to cache key generation, persistence, or eviction trigger

On cache hit, move the entry to the end of Map iteration order so
recently accessed entries survive eviction. Adds a test verifying
the oldest-but-recently-accessed entry is kept while the true LRU
entry is evicted.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@imperion402

Copy link
Copy Markdown

Problem: Trending/viral posts appear repeatedly in feeds. Under FIFO, a post seen 50 times gets evicted just because 500 other posts came after it, forcing a redundant LLM call next time the user scrolls past it.

Source? That literally never happens on X.com.

@jdcodes1

Copy link
Copy Markdown
Author

Problem: Trending/viral posts appear repeatedly in feeds. Under FIFO, a post seen 50 times gets evicted just because 500 other posts came after it, forcing a redundant LLM call next time the user scrolls past it.

Source? That literally never happens on X.com.

variants of the same post, not exactly the same. happens frequently during large events- Iran, Anthropic Mythos

@imperion402

imperion402 commented Apr 12, 2026

Copy link
Copy Markdown

Problem: Trending/viral posts appear repeatedly in feeds. Under FIFO, a post seen 50 times gets evicted just because 500 other posts came after it, forcing a redundant LLM call next time the user scrolls past it.

Source? That literally never happens on X.com.

variants of the same post, not exactly the same. happens frequently during large events- Iran, Anthropic Mythos

LRU Cache would have to be an exact match -> variant perf wouldn't be improved

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.

2 participants