Skip to content

Manchester | 25-SDC-Nov | Rahwa Haile | Sprint 2 | Implement an LRU cache in Python#123

Open
RahwaZeslusHaile wants to merge 2 commits intoCodeYourFuture:mainfrom
RahwaZeslusHaile:implement_lru_cache
Open

Manchester | 25-SDC-Nov | Rahwa Haile | Sprint 2 | Implement an LRU cache in Python#123
RahwaZeslusHaile wants to merge 2 commits intoCodeYourFuture:mainfrom
RahwaZeslusHaile:implement_lru_cache

Conversation

@RahwaZeslusHaile
Copy link

Manchester | 25-SDC-Nov | Rahwa Haile | Sprint 2 | Implement an LRU cache in Python

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Title
Implement LRU Cache with O(1) Time Complexity

Description
Implements an LRU (Least Recently Used) cache that supports O(1) time complexity for all operations using a doubly-linked list and a hash map.

Features:

LruCache(limit) - Initialize cache with max capacity
get(key) - Retrieve value and mark as recently used
set(key, value)- Store/update value, evict LRU item when full

Please review my work — thank you!

@RahwaZeslusHaile RahwaZeslusHaile added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 26, 2026
Copy link

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

To better adhere to the Single-Responsibility Principle (SRP) from SOLID design principles,
it's preferable to implement the "doubly linked list" and the "LRU Cache" as separate classes, with the linked list used inside LruCache to manage ordering.

Alternatively, OrderedDict can be used directly within LruCache to maintain order.

Could you update your code using one of these approaches?

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Feb 27, 2026
@RahwaZeslusHaile
Copy link
Author

@cjyuan Thanks for the suggestion! I've refactored the code to separate concerns:

DoublyLinkedList: handles list operations
LruCache: focuses on cache logic

@RahwaZeslusHaile RahwaZeslusHaile added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 27, 2026
Copy link

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

LGTM. Well done.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Reviewed Volunteer to add when completing a review with trainee action still to take. labels Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants