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

Author: MOHD-TAHA-KHANCreated May 7, 2026Updated May 7, 2026
Labelsenhancement

Motivation

Description

Currently, the repository lacks a standardized implementation of an LRU (Least Recently Used) Cache. This is a fundamental data structure in computer science used for memory management and caching strategies.

Proposed Solution

I propose adding an LRU Cache implementation that achieves O(1) time complexity for both get and put operations by combining:

  1. A Doubly Linked List: To maintain the order of elements based on their usage.
  2. A Hash Map (Map): To provide fast access to nodes by their keys.

Implementation Details

  • BaseCache (Abstract Class): Defines the contract for cache implementations, demonstrating OOP abstraction.
  • LRUCache (Concrete Class): Extends BaseCache and manages the pointer logic for eviction and updates.
  • Generics: Supports any key-value types <K, V>.
  • Unit Tests: Comprehensive coverage for eviction, updates, and capacity constraints.

I have already implemented this locally and would like to contribute it.

Examples

No response

Possible workarounds

No response

Source: TheAlgorithms/TypeScript