Skip to content

London | 26-Jul-SDC | Roman Sanaye | Sprint 2 | Implement LRU Cache - #244

Open
RomanSanaye wants to merge 2 commits into
CodeYourFuture:mainfrom
RomanSanaye:implement-lru-cache-in-python
Open

RomanSanaye wants to merge 2 commits into
CodeYourFuture:mainfrom
RomanSanaye:implement-lru-cache-in-python

Conversation

@RomanSanaye

Copy link
Copy Markdown

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

Task code

CYF-1181

Changelist

  • Implemented an O(1) worst-case time complexity LRU Cache using a Python dictionary for instant lookups and a Doubly Linked List for tracking usage order.
  • Added strict limit validation in the constructor to raise a ValueError for zero or negative limits.
  • Handled edge cases including single-node lists, middle-node re-linking, and tail eviction.
  • Verified implementation against the provided test suite (lru_cache_test.py) with all tests passing successfully.

Questions

No questions—all unit tests passed successfully!

@RomanSanaye RomanSanaye added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 13, 2026

@cjyuan cjyuan left a comment

Copy link
Copy Markdown

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.

You could copy your linked_list.py to this folder.

Alternatively, use a suitable Python built-in class 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 Oct 13, 2026
@RomanSanaye

Copy link
Copy Markdown
Author

Hi @cjyuan ,
Great catch and thanks for pointing out the SOLID principles! I've refactored the code to completely separate the DoublyLinkedList and LruCache into distinct classes. Now, LruCache handles only cache operations and delegates all node ordering/pointer manipulation to the DoublyLinkedList to properly adhere to the Single-Responsibility Principle.

@RomanSanaye RomanSanaye added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 15, 2026

@cjyuan cjyuan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good!

@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 Oct 15, 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