Skip to content

feat: implement LRU cache eviction strategy in semanticContext middleware (#838)#856

Merged
Renu-code123 merged 1 commit intoRenu-code123:mainfrom
tanmayShinde-dev:feat/lru-cache-semantic-context
Mar 1, 2026
Merged

feat: implement LRU cache eviction strategy in semanticContext middleware (#838)#856
Renu-code123 merged 1 commit intoRenu-code123:mainfrom
tanmayShinde-dev:feat/lru-cache-semantic-context

Conversation

@tanmayShinde-dev
Copy link
Contributor

📝 Description

This PR enhances the in-memory caching mechanism in the semanticContext middleware by implementing a proper Least Recently Used (LRU) eviction strategy.

Improvements:

  • Marks cache entries as recently used on every cache hit (delete → re-set pattern).
  • Evicts the least recently used entry when CACHE_MAX_SIZE is exceeded.
  • Retains existing TTL expiration logic.
  • Ensures predictable memory usage and improved cache efficiency.

This change affects the Node.js API (backend middleware layer only).
It does not impact the Vanilla JS frontend or PWA service workers.


🔗 Related Issue

Fixes #838


🛠️ Type of Change

  • New Feature (Backend performance improvement via LRU caching)
  • 🐞 Bug Fix
  • 📝 Documentation
  • 🔐 Security/Backend
  • 📱 PWA/Offline

🧪 Testing & Validation

  • Server starts successfully without runtime errors.
  • Verified cache hit reordering logic works as expected.
  • Confirmed least recently used entries are evicted when size limit is exceeded.
  • Tested in full-stack mode with MongoDB (not required for cache logic validation).
  • Ran npm run dev and confirmed no crashes or syntax errors.

🚩 Checklist:

  • Code follows the existing folder structure (middleware/semanticContext.js).
  • No new environment variables were introduced.
  • No sensitive .env secrets or private keys were committed.
  • PR targets the main branch.

📸 Visuals (if applicable)

Not applicable — backend-only improvement.

@vercel
Copy link

vercel bot commented Mar 1, 2026

@tanmayShinde-dev is attempting to deploy a commit to the Renu's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link

github-actions bot commented Mar 1, 2026

🎉 Thanks for the PR, @tanmayShinde-dev!

We really appreciate you taking the time to contribute to ExpenseFlow! 💙


⭐ Love this project?

Please give us a star! It helps the project grow and reach more developers! 🌟

🔗 https://github.com/Renu-code123/ExpenseFlow


✅ PR Checklist

Before we review, please ensure:

  • Your code follows the project's coding standards
  • All file changes are accurate and intentional
  • You've tested your changes locally
  • Any review comments have been addressed

🙌 Thank You for Contributing!

We truly appreciate your interest in contributing to this project.

  • Please make sure your code follows the project structure
  • Add clear commit messages and comments where necessary
  • Ensure your changes do not break existing functionality

We'll review your PR as soon as possible. Keep up the great work! ✨


@vercel
Copy link

vercel bot commented Mar 1, 2026

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

Project Deployment Actions Updated (UTC)
expenseflow Ready Ready Preview, Comment Mar 1, 2026 3:55pm

@Renu-code123 Renu-code123 merged commit f4afda1 into Renu-code123:main Mar 1, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve cache eviction strategy in semanticContext middleware (LRU implementation)

2 participants