perf(core): implement multi-level LRU caching for expensive computations and data retrieval (fixes #48) - #54
Conversation
|
I have pushed a fix to resolve this issue and implement the requested caching layer. This PR strictly contains only the file changes necessary for the in-memory LRU cache integration. Technical Analysis
ECSoC26 Label RequestPlease review and add the appropriate labels. Based on the ECSoC26 guidelines, I believe this qualifies for Level 3 (Core/Arch/Perf) because it directly implements a core performance optimization (caching layer) to reduce algorithmic latency and redundant expensive computations. Additionally, please consider adding the Please review when you get a chance! |
|
I have successfully resolved the merge conflicts and merged the latest upstream/main. |
|
Hi @Omnikon-Org, I noticed this PR was merged/closed but seems to be missing the |
Summary
Implemented a multi-level LRU (Least Recently Used) caching mechanism with TTL support to optimize expensive computations and data retrieval, specifically targeting the high-latency AI model list fetches.
Motivation
Closes #48
Performance profiling revealed that repeated data fetching for remote resources (like HF models and OpenRouter models) was a primary bottleneck. Implementing this caching layer optimizes these hot paths, provides instant response times after the initial fetch, and reduces unnecessary load on primary data endpoints.
Changes
src/utils/cache.ts):ICache<T>interface.LRUCache<T>usingMapto maintain LRU eviction semantics and built-in TTL expiration.src/utils/cache.test.ts):src/stores/aiStore.ts):modelCachewith a 5-minute TTL.getHfModels()andgetOpenRouterFreeModels()to check the cache before invoking backend API requests.Acceptance Criteria
Impact & Side Effects
How to Test
npx vitest run src/utils/cache.test.tsto verify caching behavior (hit vs miss).getHfModelsorgetOpenRouterFreeModelstriggers a backend fetch only once, and subsequent calls resolve instantly from the LRU cache.Quality Checklist