{"id":27933093,"url":"https://github.com/gireeshbharmshetty/java-lru-cache","last_synced_at":"2025-05-07T04:27:23.032Z","repository":{"id":291411066,"uuid":"977536781","full_name":"gireeshbharmshetty/java-lru-cache","owner":"gireeshbharmshetty","description":"A simple LRU (Least Recently Used) Cache implementation in Java using HashMap and Doubly Linked List.","archived":false,"fork":false,"pushed_at":"2025-05-04T12:42:22.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-04T13:46:07.561Z","etag":null,"topics":["algorithms","cache","data-structures","java","lru-cache","system-design"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gireeshbharmshetty.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-04T12:41:00.000Z","updated_at":"2025-05-04T12:43:05.000Z","dependencies_parsed_at":"2025-05-04T13:56:17.612Z","dependency_job_id":null,"html_url":"https://github.com/gireeshbharmshetty/java-lru-cache","commit_stats":null,"previous_names":["gireeshbharmshetty/java-lru-cache"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gireeshbharmshetty%2Fjava-lru-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gireeshbharmshetty%2Fjava-lru-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gireeshbharmshetty%2Fjava-lru-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gireeshbharmshetty%2Fjava-lru-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gireeshbharmshetty","download_url":"https://codeload.github.com/gireeshbharmshetty/java-lru-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252812557,"owners_count":21808161,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","cache","data-structures","java","lru-cache","system-design"],"created_at":"2025-05-07T04:27:22.528Z","updated_at":"2025-05-07T04:27:23.016Z","avatar_url":"https://github.com/gireeshbharmshetty.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Java LRU Cache Implementation\n\n## Project Overview\n\nThis project provides a simple implementation of a Least Recently Used (LRU) cache in Java. An LRU cache is a fixed-size cache that automatically evicts the least recently used item when it needs to make space for a new item.\n\n## How it Works\n\nThis implementation uses a combination of two data structures:\n\n1.  **`HashMap`:** Provides O(1) average time complexity for `get` and `put` operations by storing the key and a reference to the corresponding node in the linked list.\n2.  **Doubly Linked List:** Maintains the order of usage. The most recently used item is kept at the head of the list, and the least recently used item is kept at the tail. When an item is accessed (`get`) or updated (`put`), it is moved to the head. When the cache is full and a new item is added, the item at the tail is removed.\n\nDummy `head` and `tail` nodes are used in the doubly linked list to simplify the logic for adding and removing nodes, avoiding null checks for boundary conditions.\n\n## Benefits \u0026 Relevance\n\n*   **Understanding Cache Eviction:** Demonstrates a common cache eviction strategy used in many systems.\n*   **Data Structure Practice:** Provides practical application of HashMaps and Doubly Linked Lists.\n*   **Interview Relevance:** LRU Cache implementation is a classic question in software engineering interviews, especially for roles involving system design or backend development.\n*   **Concurrency (Note):** This specific implementation is **not** thread-safe. For concurrent environments, synchronization mechanisms (like `ConcurrentHashMap` and explicit locking) would be required.\n\n## How to Use/Run\n\n1.  **Compile:** You can compile the Java files using a Java Development Kit (JDK):\n    ```bash\n    javac src/main/java/com/gireesh/cache/*.java\n    ```\n2.  **Run the Demo:** Execute the `LRUCacheDemo` class to see the cache in action:\n    ```bash\n    java -cp src/main/java com.gireesh.cache.LRUCacheDemo\n    ```\n    The demo will show items being added, accessed, and evicted based on the LRU policy.\n\n## Files\n\n*   `src/main/java/com/gireesh/cache/CacheNode.java`: Represents a node in the doubly linked list.\n*   `src/main/java/com/gireesh/cache/LRUCache.java`: The main LRU Cache implementation class.\n*   `src/main/java/com/gireesh/cache/LRUCacheDemo.java`: A simple class to demonstrate the cache functionality.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgireeshbharmshetty%2Fjava-lru-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgireeshbharmshetty%2Fjava-lru-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgireeshbharmshetty%2Fjava-lru-cache/lists"}