Skip to content

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

@MOHD-TAHA-KHAN

Description

@MOHD-TAHA-KHAN

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions