CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history
debt-cache.ts
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| fa97fd1 | 1 | /** |
| 2 | * In-memory cache for DebtReport objects. | |
| 3 | * Reports are invalidated after 1 hour. | |
| 4 | */ | |
| 5 | ||
| 6 | import type { DebtReport } from "./debt-analyzer"; | |
| 7 | ||
| 8 | interface CacheEntry { | |
| 9 | report: DebtReport; | |
| 10 | cachedAt: number; | |
| 11 | } | |
| 12 | ||
| 13 | const CACHE_TTL_MS = 60 * 60 * 1000; // 1 hour | |
| 14 | ||
| 15 | const cache = new Map<string, CacheEntry>(); | |
| 16 | ||
| 17 | /** Returns the cached DebtReport if it's less than 1 hour old, else null. */ | |
| 18 | export function getDebtReport(repoId: string): DebtReport | null { | |
| 19 | const entry = cache.get(repoId); | |
| 20 | if (!entry) return null; | |
| 21 | if (Date.now() - entry.cachedAt > CACHE_TTL_MS) { | |
| 22 | cache.delete(repoId); | |
| 23 | return null; | |
| 24 | } | |
| 25 | return entry.report; | |
| 26 | } | |
| 27 | ||
| 28 | /** Store a DebtReport in the cache. */ | |
| 29 | export function setDebtReport(repoId: string, report: DebtReport): void { | |
| 30 | cache.set(repoId, { report, cachedAt: Date.now() }); | |
| 31 | } | |
| 32 | ||
| 33 | /** Evict the cached report for a repository. */ | |
| 34 | export function invalidateDebtReport(repoId: string): void { | |
| 35 | cache.delete(repoId); | |
| 36 | } | |
| 37 | ||
| 38 | // ─── In-memory job status ───────────────────────────────────────────────────── | |
| 39 | ||
| 40 | export type JobStatus = "pending" | "running" | "done" | "error"; | |
| 41 | ||
| 42 | interface JobEntry { | |
| 43 | status: JobStatus; | |
| 44 | error?: string; | |
| 45 | startedAt: number; | |
| 46 | } | |
| 47 | ||
| 48 | const jobs = new Map<string, JobEntry>(); | |
| 49 | ||
| 50 | export function getJobStatus(repoId: string): JobEntry | null { | |
| 51 | return jobs.get(repoId) ?? null; | |
| 52 | } | |
| 53 | ||
| 54 | export function setJobStatus(repoId: string, status: JobStatus, error?: string): void { | |
| 55 | jobs.set(repoId, { status, error, startedAt: Date.now() }); | |
| 56 | } |