{"id":24326123,"url":"https://github.com/zekfad/lru_cache","last_synced_at":"2025-09-27T10:32:31.599Z","repository":{"id":270948881,"uuid":"768877493","full_name":"Zekfad/lru_cache","owner":"Zekfad","description":"LRU (Least recently used) cache with additional weak map layer.","archived":false,"fork":false,"pushed_at":"2025-01-04T08:54:01.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-04T09:55:13.768Z","etag":null,"topics":["cache","dart","dart-package","lru","lru-cache","lrucache"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Zekfad.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-03-07T22:38:31.000Z","updated_at":"2025-01-04T08:54:05.000Z","dependencies_parsed_at":"2025-01-04T09:55:21.889Z","dependency_job_id":"a1b98f00-e970-4173-83fa-207321e3b535","html_url":"https://github.com/Zekfad/lru_cache","commit_stats":null,"previous_names":["zekfad/lru_cache"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zekfad%2Flru_cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zekfad%2Flru_cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zekfad%2Flru_cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zekfad%2Flru_cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Zekfad","download_url":"https://codeload.github.com/Zekfad/lru_cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234427684,"owners_count":18831128,"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","dart-package","lru","lru-cache","lrucache"],"created_at":"2025-01-17T20:35:14.857Z","updated_at":"2025-09-27T10:32:31.590Z","avatar_url":"https://github.com/Zekfad.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LRU Cache\n\n[![pub package](https://img.shields.io/pub/v/lru.svg)](https://pub.dev/packages/lru)\n[![package publisher](https://img.shields.io/pub/publisher/lru.svg)](https://pub.dev/packages/lru/publisher)\n\nCache based on Least Recently Used eviction strategy.\n\nOptionally supports caching above normal capacity via Week references\n(such values are cached until they are garbage collected normally).\n\nAddition implementation for `TypedData` with capacity in bytes.\nThat can be used for caching buffers such as raw images.\n\n## Features\n\n* Supports full `Map` interface.\n* Store `TypedData` and evict entries on bytes capacity overflow via\n  `LruTypedDataCache`.\n* Expando compatible objects can be optionally cached via `LruWeakCache`.\n\n## Usage\n\nCreate cache, add values, when capacity is reached old elements will be removed;\n\n```dart\n// Cannot use weak cache, because String is not supported by Expando\nfinal cache = LruCache\u003cint, String\u003e(2);\n\ncache[0] = '0';\ncache[1] = '1';\n\ncache[0]; // try to touch\n\ncache[2] = '2'; // key 1 is evicted here\n\n\nprint(cache[0]); // 0\nprint(cache[1]); // null\nprint(cache[2]); // 2\n```\n\nExample with bytes capacity for `TypedData`.\n\n```dart\n// Use capacityInBytes as additional eviction strategy, on overflow\n// old elements will be removed same as normal LRU capacity\nfinal cache = LruTypedDataCache\u003cint, Uint8List\u003e(capacity: 100, capacityInBytes: 2);\n\ncache[0] = Uint8List(1)..[0] = 0;\ncache[1] = Uint8List(1)..[0] = 1;\n\ncache[0]; // try to touch\n\ncache[2] = Uint8List(1)..[0] = 2;\n\nprint(cache[0]); // [0]\nprint(cache[1]); // null\nprint(cache[2]); // [2]\n```\n\nWeak cache is a bit more complicated, because it's behavior is depended on Dart\ngarbage collection. Elements that are normally would be removed from LRU cache\nare temporarily stored in weak cache that doesn't create strong references to\nstored objects.\n\nFollowing is example of Weak Cache support:\n\n```dart\n/// Helper class to demonstrate LruWeakCache\nclass Key {\n  const Key(this.key);\n  final String key;\n  @override\n  String toString() =\u003e key;\n}\n\nvoid main() {\n  final cache = LruWeakCache\u003cint, Key\u003e(2);\n\n  cache[0] = Key('0');\n  cache[1] = Key('1');\n  cache[2] = Key('2'); // key 0 is evicted from main LRU and moved to weak cache\n\n  // if key 0 is not garbage collected yet\n  // key 1 is moved to weak cache, and key 0 is restored\n  cache[0];\n\n  print(cache[0]); // 0 if key 0 wasn't garbage collected\n  print(cache[1]); // 1 if key 0 was garbage collected or if key 1 wasn't GC'd\n  print(cache[2]); // 2\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzekfad%2Flru_cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzekfad%2Flru_cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzekfad%2Flru_cache/lists"}