Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
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.

debt-cache.tsBlame56 lines · 1 contributor
fa97fd1Claude1/**
2 * In-memory cache for DebtReport objects.
3 * Reports are invalidated after 1 hour.
4 */
5
6import type { DebtReport } from "./debt-analyzer";
7
8interface CacheEntry {
9 report: DebtReport;
10 cachedAt: number;
11}
12
13const CACHE_TTL_MS = 60 * 60 * 1000; // 1 hour
14
15const cache = new Map<string, CacheEntry>();
16
17/** Returns the cached DebtReport if it's less than 1 hour old, else null. */
18export 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. */
29export 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. */
34export function invalidateDebtReport(repoId: string): void {
35 cache.delete(repoId);
36}
37
38// ─── In-memory job status ─────────────────────────────────────────────────────
39
40export type JobStatus = "pending" | "running" | "done" | "error";
41
42interface JobEntry {
43 status: JobStatus;
44 error?: string;
45 startedAt: number;
46}
47
48const jobs = new Map<string, JobEntry>();
49
50export function getJobStatus(repoId: string): JobEntry | null {
51 return jobs.get(repoId) ?? null;
52}
53
54export function setJobStatus(repoId: string, status: JobStatus, error?: string): void {
55 jobs.set(repoId, { status, error, startedAt: Date.now() });
56}