Spaces:
Sleeping
Sleeping
| // agentLoop/archCtxCache.ts | |
| // S567: estratto da agentLoop.ts — cache con TTL 5s per buildArchContext (S440). | |
| // Evita O(n) sincrono ad ogni rebuild del system prompt. | |
| import { buildArchContext } from "@/lib/projectArchGraph"; | |
| let _cache: { val: string; at: number } = { val: "", at: 0 }; | |
| /** | |
| * Restituisce buildArchContext() con cache in-memory TTL 5s. | |
| * Chiamato ad ogni _rebuildSys() → esecuzione O(1) se recente, O(n) solo alla prima | |
| * chiamata o dopo 5 secondi dall'ultima (ad es. dopo modifica file). | |
| */ | |
| export function buildArchCtxCached(): string { | |
| if (Date.now() - _cache.at < 5_000) return _cache.val; | |
| try { _cache = { val: buildArchContext(), at: Date.now() }; } | |
| catch { _cache = { val: "", at: Date.now() }; } | |
| return _cache.val; | |
| } | |