Skip to content

feat(utils): add cache utility#17

Merged
maitamdev merged 1 commit intomainfrom
feat/cache-utils
Mar 4, 2026
Merged

feat(utils): add cache utility#17
maitamdev merged 1 commit intomainfrom
feat/cache-utils

Conversation

@maitamdev
Copy link
Copy Markdown
Owner

@maitamdev maitamdev commented Mar 4, 2026

In-memory cache with TTL for API response caching.


Summary by cubic

Added a simple in-memory cache for API responses to cut repeated requests and speed up the app.

  • New Features
    • SimpleCache utility with set, get, has, delete, clear, size.
    • TTL support with a 5-minute default; override per entry via set(key, value, ttlMs).
    • Exported appCache singleton for shared use across modules.

Written for commit 1820ffd. Summary will update on new commits.

Co-authored-by: DHV Team <dhvteam@users.noreply.github.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dhv-guiding-light Ready Ready Preview, Comment Mar 4, 2026 7:23pm

@maitamdev maitamdev merged commit 72ed673 into main Mar 4, 2026
1 of 2 checks passed
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 4, 2026

Warning

Rate limit exceeded

@maitamdev has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 30 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ac65c997-3de4-4da4-a472-5831e425cb60

📥 Commits

Reviewing files that changed from the base of the PR and between d69578e and 1820ffd.

📒 Files selected for processing (1)
  • src/utils/cacheUtils.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/cache-utils

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/utils/cacheUtils.ts">

<violation number="1" location="src/utils/cacheUtils.ts:14">
P2: `has()` is incorrect for valid cached `null` values because it infers existence from `get() !== null` instead of checking key/expiry directly.</violation>

<violation number="2" location="src/utils/cacheUtils.ts:17">
P2: `size()` returns total map entries, including expired ones, because it does not purge stale keys before counting.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

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; }
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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant