From 5f063f54a2443fccf8f9767ad817a23348151e8a Mon Sep 17 00:00:00 2001 From: 6figpsolseeker <6figpsolseeker@gmail.com> Date: Thu, 9 Apr 2026 01:19:10 -0400 Subject: [PATCH] fix(adl): promote cached entries on hit so eviction is LRU not FIFO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The /adl/:slab handler used an in-memory cache with capacity-based eviction via `adlCache.keys().next().value`, which deletes the oldest *insertion*. Cache hits did not reposition the entry, so a hot slab inserted early would be evicted before cold slabs inserted later. Each cache miss is expensive (Solana RPC `fetchSlab` plus full account parsing and ranking), so a hot key getting evicted under capacity pressure caused redundant RPC load and user-visible latency. Add the same promotion-on-hit pattern already used in `src/routes/oracle-router.ts` (delete + reinsert before returning the cached payload). The eviction logic at the bottom of the handler is unchanged — it now effectively evicts the least-recently-used entry because the Map's iteration order tracks recency. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/routes/adl.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/routes/adl.ts b/src/routes/adl.ts index 201c1b9..5496db1 100644 --- a/src/routes/adl.ts +++ b/src/routes/adl.ts @@ -165,6 +165,11 @@ export function adlRoutes(): Hono { // Check cache to avoid redundant expensive RPC calls const cached = adlCache.get(slab); if (cached && Date.now() - cached.fetchedAt < ADL_CACHE_TTL_MS) { + // Promote to most-recently-used so the FIFO-by-insertion eviction + // at lines below behaves as LRU. Without this, hot keys inserted + // early get evicted while cold keys inserted later survive. + adlCache.delete(slab); + adlCache.set(slab, cached); return c.json(cached.data, 200, { "X-Cache": "HIT" }); }