{"id":23144459,"url":"https://github.com/neeru1207/selective_lru_cache_decorator","last_synced_at":"2025-08-02T02:39:30.439Z","repository":{"id":102547347,"uuid":"286207322","full_name":"neeru1207/Selective_LRU_Cache_Decorator","owner":"neeru1207","description":"A Python Decorator similar to but simpler than functools.lru_cache with the extra ability to select parameters","archived":false,"fork":false,"pushed_at":"2020-10-11T05:31:37.000Z","size":151,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-09T22:16:27.765Z","etag":null,"topics":["functools","hacktoberfest","lru-cache","memoize-decorator","python-decorator"],"latest_commit_sha":null,"homepage":"","language":"Python","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/neeru1207.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-08-09T09:37:04.000Z","updated_at":"2020-10-11T05:31:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"da6f6542-6cb1-4343-83e4-947bcf446ce4","html_url":"https://github.com/neeru1207/Selective_LRU_Cache_Decorator","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/neeru1207%2FSelective_LRU_Cache_Decorator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neeru1207%2FSelective_LRU_Cache_Decorator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neeru1207%2FSelective_LRU_Cache_Decorator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neeru1207%2FSelective_LRU_Cache_Decorator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neeru1207","download_url":"https://codeload.github.com/neeru1207/Selective_LRU_Cache_Decorator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247174460,"owners_count":20896078,"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":["functools","hacktoberfest","lru-cache","memoize-decorator","python-decorator"],"created_at":"2024-12-17T15:16:15.243Z","updated_at":"2025-04-04T12:17:07.572Z","avatar_url":"https://github.com/neeru1207.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Selective_LRU_Cache_Decorator\nA Python Decorator similar to but much simpler than functools.lru_cache with the extra ability to select parameters. It can be used to memoize recursive functions.\n\n## Usage\n* Clone this repository and place the lru_cache module in the working directory.\n* Import the LRU Cache in your Python code by typing the below command.\n\n  ```python\n  from lru_cache.lru_cache import SelectiveLRUCache\n  ```\n* Decorate a function with the cache by placing the below command just above the function definition. The decorator takes two parameters - maxsize (the maximum size of the LRU Cache) and parameters. The \"parameters\" parameter is a lambda function which decides which parameters to select. In the below example, the \"parameters\" lambda selects only the first parameter.\n\n  ```python\n  @SelectiveLRUCache(parameters=lambda x:(x[0],), maxsize=None)\n  def fibonacci(n, cntr):\n  ```\n * The \"parameters\" lambda function takes the list of parameters as input and outputs a tuple of the selected list of parameters. Here the lambda selects the first and third parameters from the list of parameters.\n \n   ```python\n   @SelectiveLRUCache(parameters=lambda x:(x[0], x[2]))\n   ```\n \n## Performance\n * When tested on the recursive fibonacci function, a **46000 times** faster execution and a **29000 times** reduction in the number of function calls was achieved.\n * Fibonacci(40) without the cache took *331160289* function calls and *92.686* seconds as shown below:\n \n    ![](https://github.com/neeru1207/Selective_LRU_Cache_Decorator/blob/master/Without_Cache_Speed.png)\n  \n * Fibonacci(40) with the cache took *1140* function calls and only *0.002* seconds to execute as shown below:\n \n    ![](https://github.com/neeru1207/Selective_LRU_Cache_Decorator/blob/master/With_Cache_Speed.png)\n  \n## Contributing\n * Feel free to open an issue if any bug is found.\n * Pull requests are welcome. Just make sure to contribute readable, well commented, and tested code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneeru1207%2Fselective_lru_cache_decorator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneeru1207%2Fselective_lru_cache_decorator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneeru1207%2Fselective_lru_cache_decorator/lists"}