{"id":18954190,"url":"https://github.com/tanmaylaud/memory_cache_java","last_synced_at":"2026-03-30T10:30:18.190Z","repository":{"id":125877718,"uuid":"267893732","full_name":"tanmaylaud/memory_cache_java","owner":"tanmaylaud","description":"In computing, cache algorithms (also frequently called cache replacement algorithms or cache replacement policies) are optimizing instructions, or algorithms, that a computer program or a hardware-maintained structure can utilize in order to manage a cache of information stored on the computer. Caching improves performance by keeping recent or often-used data items in memory locations that are faster or computationally cheaper to access than normal memory stores. When the cache is full, the algorithm must choose which items to discard to make room for the new ones.","archived":false,"fork":false,"pushed_at":"2020-05-29T15:43:59.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-01T03:21:25.912Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","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/tanmaylaud.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}},"created_at":"2020-05-29T15:37:29.000Z","updated_at":"2020-05-29T15:44:06.000Z","dependencies_parsed_at":"2023-07-08T04:30:53.840Z","dependency_job_id":null,"html_url":"https://github.com/tanmaylaud/memory_cache_java","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanmaylaud%2Fmemory_cache_java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanmaylaud%2Fmemory_cache_java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanmaylaud%2Fmemory_cache_java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanmaylaud%2Fmemory_cache_java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tanmaylaud","download_url":"https://codeload.github.com/tanmaylaud/memory_cache_java/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239952638,"owners_count":19723924,"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":[],"created_at":"2024-11-08T13:43:22.543Z","updated_at":"2026-03-30T10:30:18.099Z","avatar_url":"https://github.com/tanmaylaud.png","language":"Java","readme":"# memory_cache_java\n#### In computing, cache algorithms (also frequently called cache replacement algorithms or cache replacement policies) are optimizing instructions, or algorithms, that a computer program or a hardware-maintained structure can utilize in order to manage a cache of information stored on the computer. Caching improves performance by keeping recent or often-used data items in memory locations that are faster or computationally cheaper to access than normal memory stores. When the cache is full, the algorithm must choose which items to discard to make room for the new ones.\n\n## This project contains Java implementation of LRU and LFU cache with O(1) complexity for both get() and put() operations.\n\n## LFU Cache :\n#### Problem Statement\n\nDesign and implement a data structure for Least Frequently Used (LFU) cache. It should support the following operations: get and put.\n\nget(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.\nput(key, value) - Set or insert the value if the key is not already present. When the cache reaches its capacity, it should invalidate the least frequently used item before inserting a new item. For the purpose of this problem, when there is a tie (i.e., two or more keys that have the same frequency), the least recently used key would be evicted.\n\nNote that the number of times an item is used is the number of calls to the get and put functions for that item since it was inserted. This number is set to zero when the item is removed.\nFollow up:\nCould you do both operations in O(1) time complexity?\n\n \n\nExample:\n```\nLFUCache cache = new LFUCache( 2 /* capacity */ );\n\ncache.put(1, 1);\ncache.put(2, 2);\ncache.get(1);       // returns 1\ncache.put(3, 3);    // evicts key 2\ncache.get(2);       // returns -1 (not found)\ncache.get(3);       // returns 3.\ncache.put(4, 4);    // evicts key 1.\ncache.get(1);       // returns -1 (not found)\ncache.get(3);       // returns 3\ncache.get(4);       // returns 4\n```\n\n## LRU Cache :\n#### Problem Statement\n\nDesign and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.\n\nget(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.\nput(key, value) - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.\n\nThe cache is initialized with a positive capacity.\n\nFollow up:\nCould you do both operations in O(1) time complexity?\n\nExample:\n```\nLRUCache cache = new LRUCache( 2 /* capacity */ );\n\ncache.put(1, 1);\ncache.put(2, 2);\ncache.get(1);       // returns 1\ncache.put(3, 3);    // evicts key 2\ncache.get(2);       // returns -1 (not found)\ncache.put(4, 4);    // evicts key 1\ncache.get(1);       // returns -1 (not found)\ncache.get(3);       // returns 3\ncache.get(4);       // returns 4\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanmaylaud%2Fmemory_cache_java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftanmaylaud%2Fmemory_cache_java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanmaylaud%2Fmemory_cache_java/lists"}