Skip to content

feat: add LRU Cache with BaseCache abstraction (#304)#305

Open
MOHD-TAHA-KHAN wants to merge 1 commit intoTheAlgorithms:masterfrom
MOHD-TAHA-KHAN:feat/lru-cache-oop
Open

feat: add LRU Cache with BaseCache abstraction (#304)#305
MOHD-TAHA-KHAN wants to merge 1 commit intoTheAlgorithms:masterfrom
MOHD-TAHA-KHAN:feat/lru-cache-oop

Conversation

@MOHD-TAHA-KHAN
Copy link
Copy Markdown

@MOHD-TAHA-KHAN MOHD-TAHA-KHAN commented May 7, 2026

📝 Description

This PR introduces a high-performance LRU (Least Recently Used) Cache implementation. It is designed for educational purposes, showcasing how to combine a Hash Map and a Doubly Linked List to achieve constant time complexity for cache operations.

Resolves #304

🚀 Key Features

  • OOP Architecture: Uses an Abstract Base Class (BaseCache) and Inheritance to follow professional software design patterns.
  • Efficient Performance: - get(key): O(1)
    • put(key, value): O(1)
  • Memory Safety: Automatically evicts the least recently used item when the capacity limit is reached.
  • Generic Support: Implemented with TypeScript Generics to support any data types.

🧪 Testing

Includes 5+ unit tests in data_structures/cache/__tests__/LRUCache.test.ts covering:

  • Basic storage and retrieval.
  • Eviction logic when exceeding capacity.
  • Moving accessed items to the "Most Recently Used" position.
  • Handling capacity of 1.

📊 Complexity

  • Time Complexity: $O(1)$ for all operations.
  • Space Complexity: $O(C)$ where $C$ is the capacity of the cache.

Self-Review Checklist:

  • Code follows project naming conventions.
  • No any types used.
  • Linting and Formatting passed.

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.

[FEATURE]: [ENHANCEMENT]: Add LRU (Least Recently Used) Cache implementation

1 participant