feat: add bounded prediction cache (max 100 entries, FIFO eviction)
- Before inserting into predictionCacheRef, check if size >= 100 - If so, evict oldest entry via cache.keys().next().value (FIFO) - Applied at both cache write sites (lines ~549 and ~671 in page.tsx) - Marks task 8.5 as done in tasks.md Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
acf31d3edf
commit
8395f23744
2 changed files with 12 additions and 4 deletions
|
|
@ -544,9 +544,13 @@ export default function Home() {
|
|||
|
||||
const data = await response.json();
|
||||
|
||||
// Cache the results
|
||||
// Cache the results (bounded: max 100 entries, FIFO eviction)
|
||||
if (cacheKey) {
|
||||
predictionCacheRef.current.set(cacheKey, {
|
||||
const cache = predictionCacheRef.current;
|
||||
if (cache.size >= 100) {
|
||||
cache.delete(cache.keys().next().value);
|
||||
}
|
||||
cache.set(cacheKey, {
|
||||
spans: data.spans,
|
||||
predictions: data.predictions,
|
||||
modelVersion: data.model_info.model_version,
|
||||
|
|
@ -668,7 +672,11 @@ export default function Home() {
|
|||
|
||||
const cacheKey = generateCacheKey(activeChartId, data.model_info.model_version);
|
||||
if (cacheKey) {
|
||||
predictionCacheRef.current.set(cacheKey, {
|
||||
const cache = predictionCacheRef.current;
|
||||
if (cache.size >= 100) {
|
||||
cache.delete(cache.keys().next().value);
|
||||
}
|
||||
cache.set(cacheKey, {
|
||||
spans: data.spans,
|
||||
predictions: data.predictions,
|
||||
modelVersion: data.model_info.model_version,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue