Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/utils/cacheUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Simple in-memory cache with TTL
interface CacheEntry<T> { value: T; expiresAt: number; }
class SimpleCache {
private cache = new Map<string, CacheEntry<unknown>>();
set<T>(key: string, value: T, ttlMs: number = 300000): void {
this.cache.set(key, { value, expiresAt: Date.now() + ttlMs });
}
get<T>(key: string): T | null {
const entry = this.cache.get(key);
if (!entry) return null;
if (Date.now() > entry.expiresAt) { this.cache.delete(key); return null; }
return entry.value as T;
}
has(key: string): boolean { return this.get(key) !== null; }
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: has() is incorrect for valid cached null values because it infers existence from get() !== null instead of checking key/expiry directly.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/utils/cacheUtils.ts, line 14:

<comment>`has()` is incorrect for valid cached `null` values because it infers existence from `get() !== null` instead of checking key/expiry directly.</comment>

<file context>
@@ -0,0 +1,19 @@
+    if (Date.now() > entry.expiresAt) { this.cache.delete(key); return null; }
+    return entry.value as T;
+  }
+  has(key: string): boolean { return this.get(key) !== null; }
+  delete(key: string): void { this.cache.delete(key); }
+  clear(): void { this.cache.clear(); }
</file context>
Fix with Cubic

delete(key: string): void { this.cache.delete(key); }
clear(): void { this.cache.clear(); }
size(): number { return this.cache.size; }
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: size() returns total map entries, including expired ones, because it does not purge stale keys before counting.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/utils/cacheUtils.ts, line 17:

<comment>`size()` returns total map entries, including expired ones, because it does not purge stale keys before counting.</comment>

<file context>
@@ -0,0 +1,19 @@
+  has(key: string): boolean { return this.get(key) !== null; }
+  delete(key: string): void { this.cache.delete(key); }
+  clear(): void { this.cache.clear(); }
+  size(): number { return this.cache.size; }
+}
+export const appCache = new SimpleCache();
</file context>
Fix with Cubic

}
export const appCache = new SimpleCache();
Loading