{"id":21669823,"url":"https://github.com/ashtanko/lru_cache_dart","last_synced_at":"2026-01-11T13:30:52.589Z","repository":{"id":246853305,"uuid":"824340584","full_name":"ashtanko/lru_cache_dart","owner":"ashtanko","description":"🗄️ LRU Cache Implementation in Dart: A straightforward implementation of a Least Recently Used (LRU) cache in Dart, designed to efficiently manage memory by storing a limited number of items and removing the least recently accessed ones. Perfect for optimizing data retrieval in your applications.","archived":false,"fork":false,"pushed_at":"2025-01-08T00:16:48.000Z","size":35,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-08T07:53:42.803Z","etag":null,"topics":["cache","dart","flutter","lru-cache"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/lru_cache","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ashtanko.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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":"2024-07-04T23:11:45.000Z","updated_at":"2025-01-08T00:16:51.000Z","dependencies_parsed_at":"2024-07-05T14:44:19.833Z","dependency_job_id":null,"html_url":"https://github.com/ashtanko/lru_cache_dart","commit_stats":null,"previous_names":["ashtanko/lru_cache","ashtanko/lru_cache_dart"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashtanko%2Flru_cache_dart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashtanko%2Flru_cache_dart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashtanko%2Flru_cache_dart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashtanko%2Flru_cache_dart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ashtanko","download_url":"https://codeload.github.com/ashtanko/lru_cache_dart/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253025337,"owners_count":21842409,"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":["cache","dart","flutter","lru-cache"],"created_at":"2024-11-25T12:25:23.461Z","updated_at":"2026-01-11T13:30:52.582Z","avatar_url":"https://github.com/ashtanko.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"## LruCache Dart Package\n\n`lru_cache` is a Dart package that provides a simple and efficient implementation of an LRU (Least Recently Used) cache. This package uses Dart's built-in `LinkedHashMap` to maintain the order of elements based on their access history, making it suitable for scenarios where you want to limit the number of cached items and evict the least recently used items when the cache reaches its maximum capacity.\n\n[![Coverage](https://github.com/ashtanko/lru_cache/actions/workflows/coverage.yml/badge.svg)](https://github.com/ashtanko/lru_cache/actions/workflows/coverage.yml)\n[![Dart CI](https://github.com/ashtanko/lru_cache/actions/workflows/build.yml/badge.svg)](https://github.com/ashtanko/lru_cache/actions/workflows/build.yml)\n\n[![lru_cache](https://img.shields.io/pub/v/lru_cache?label=lru_cache)](https://pub.dev/packages/lru_cache)\n\n[![CodeFactor](https://www.codefactor.io/repository/github/ashtanko/lru_cache_dart/badge)](https://www.codefactor.io/repository/github/ashtanko/lru_cache_dart)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/a03583ebe6b945c1b2c594b5809e908f)](https://app.codacy.com/gh/ashtanko/lru_cache/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_grade)\n[![codecov](https://codecov.io/gh/ashtanko/lru_cache_dart/graph/badge.svg?token=V9O0ALxsV1)](https://codecov.io/gh/ashtanko/lru_cache_dart)\n[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/a03583ebe6b945c1b2c594b5809e908f)](https://app.codacy.com/gh/ashtanko/lru_cache/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_coverage)\n\n### Features\n\n- **LRU (Least Recently Used) Cache**: Keeps track of the most recently accessed items and evicts the least recently used items when the cache reaches its maximum size.\n\n- **Customizable Size Calculation**: Allows customization of how the size of cached items is calculated through a `sizeOf` method, which can be overridden to fit specific use cases.\n\n- **Thread-safe Operations**: Uses synchronized methods to ensure thread safety when accessing and modifying the cache, making it safe for concurrent use.\n\n## Getting started 🎉\n\nTo use `lru_cache` in your Dart project, add it to your `pubspec.yaml`:\n\n```dart\ndependencies:\n  lru_cache: ^latest_version\n```\n\n## Usage\nHere's an example of how to use the LruCache class:\n\n```dart\nimport 'package:lru_cache/lru_cache.dart';\n\nvoid main() {\n  // Create an LruCache with a maximum size of 2\n  final cache = LruCache\u003cString, String\u003e(2);\n\n  // Put key-value pairs into the cache\n  cache.put('key1', 'value1');\n  cache.put('key2', 'value2');\n\n  // Retrieve values from the cache\n  print(cache.get('key1')); // Prints 'value1'\n  print(cache.get('key2')); // Prints 'value2'\n\n  // Add another key-value pair, evicting the least recently used item\n  cache.put('key3', 'value3');\n  print(cache.get('key1')); // Prints 'null' because 'key1' was evicted\n\n  // Retrieve the remaining items from the cache\n  print(cache.get('key2')); // Prints 'value2'\n  print(cache.get('key3')); // Prints 'value3'\n\n  // Display cache statistics\n  print(cache.toString()); // Prints 'LruCache[maxSize=2,hits=2,misses=1,hitRate=66%]'\n}\n```\n\n## Contributing\n\nContributions are welcome! Please read the contributing guide to learn how to contribute to the project and set up a development environment.\n\n## License\n\n```plain\nMIT License\n\nCopyright (c) 2024 Oleksii Shtanko\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashtanko%2Flru_cache_dart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fashtanko%2Flru_cache_dart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashtanko%2Flru_cache_dart/lists"}