{"id":26964558,"url":"https://github.com/shellwen/lru-cache-mbt","last_synced_at":"2026-02-06T16:05:47.369Z","repository":{"id":282111309,"uuid":"947476902","full_name":"ShellWen/lru-cache-mbt","owner":"ShellWen","description":"A high-performance LRU cache implementation in MoonBit.","archived":false,"fork":false,"pushed_at":"2025-08-15T12:08:43.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-08T04:42:19.064Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"MoonBit","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ShellWen.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"zenodo":null}},"created_at":"2025-03-12T18:44:22.000Z","updated_at":"2025-08-15T12:08:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"9f447ea4-c394-4f2d-9f7d-ae2b40e3c3b3","html_url":"https://github.com/ShellWen/lru-cache-mbt","commit_stats":null,"previous_names":["shellwen/lru-cache-mbt"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ShellWen/lru-cache-mbt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShellWen%2Flru-cache-mbt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShellWen%2Flru-cache-mbt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShellWen%2Flru-cache-mbt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShellWen%2Flru-cache-mbt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ShellWen","download_url":"https://codeload.github.com/ShellWen/lru-cache-mbt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShellWen%2Flru-cache-mbt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29167870,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T15:38:29.831Z","status":"ssl_error","status_checked_at":"2026-02-06T15:37:48.592Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2025-04-03T06:33:58.322Z","updated_at":"2026-02-06T16:05:47.364Z","avatar_url":"https://github.com/ShellWen.png","language":"MoonBit","readme":"# 🧠 LRU Cache for MoonBit\n\n[English](https://github.com/ShellWen/lru-cache-mbt/blob/master/README.md) | [简体中文](https://github.com/ShellWen/lru-cache-mbt/blob/master/README_zh_CN.md)\n\n[![License](https://img.shields.io/github/license/ShellWen/lru-cache-mbt)](LICENSE)\n\n**LRU Cache** is a high-performance Least Recently Used (LRU) cache implementation in MoonBit. It provides constant-time complexity for common operations and automatically manages capacity with an efficient eviction policy.\n\n🚀 **Key Features**\n\n- ⚡ **Fast Operations** – All operations run in O(1) time complexity\n- 🔄 **Automatic Eviction** – Automatically removes least recently used items when capacity is reached\n- 🛠 **Easy to Use** – Simple API for quick integration\n- ✅ **Well-Tested** – Comes with comprehensive unit tests\n- 🔧 **Type Safe** – Fully type-safe implementation for any key-value pair types\n\n---\n\n## 📥 Installation\n\n```\nmoon add ShellWen/lru_cache\n```\n\n## 🚀 Usage Guide\n\n### Basic Usage\n\nThe simplest way to use the LRU cache is to create a new instance with a specified capacity:\n\n```moonbit\n// Create a cache with capacity 100\nlet cache : LruCache[String, Int] = LruCache::new(100)\n\n// Add items to cache\ncache.put(\"key1\", 100)\ncache.put(\"key2\", 200)\n\n// Get items from cache\nlet value1 = cache.get(\"key1\") // Returns Some(100)\nlet value2 = cache.get(\"nonexistent\") // Returns None\n```\n\n### Key Features Explained\n\n#### 1. Automatic Eviction\n\nWhen the cache reaches its capacity, the least recently used item is automatically removed:\n\n```moonbit\nlet cache : LruCache[String, Int] = LruCache::new(2) // Cache with capacity 2\ncache.put(\"key1\", 100)\ncache.put(\"key2\", 200)\ncache.put(\"key3\", 300) // This will evict \"key1\" as it's the least recently used\n\nlet val1 = cache.get(\"key1\") // Returns None, as \"key1\" was evicted\nlet val2 = cache.get(\"key2\") // Returns Some(200)\nlet val3 = cache.get(\"key3\") // Returns Some(300)\n```\n\n#### 2. LRU Order Update\n\nItems are reordered when accessed, keeping the most recently used items in the cache:\n\n```moonbit\nlet cache : LruCache[String, Int] = LruCache::new(2)\ncache.put(\"key1\", 100)\ncache.put(\"key2\", 200)\n\n// Accessing \"key1\" makes it the most recently used\nlet _ = cache.get(\"key1\")\n\n// Adding a new item will now evict \"key2\" instead of \"key1\"\ncache.put(\"key3\", 300)\n\nlet val1 = cache.get(\"key1\") // Returns Some(100)\nlet val2 = cache.get(\"key2\") // Returns None, as \"key2\" was evicted\nlet val3 = cache.get(\"key3\") // Returns Some(300)\n```\n\n#### 3. Custom Key Types\n\nYou can use any key type that implements `Eq + Hash`:\n\n```moonbit\nstruct CustomKey { id: Int } derive(Eq, Hash)\n\nlet cache : LruCache[CustomKey, String] = LruCache::new(10)\ncache.put({id: 1}, \"Value for key 1\")\ncache.put({id: 2}, \"Value for key 2\")\n\nlet value = cache.get({id: 1}) // Returns Some(\"Value for key 1\")\n```\n\n## 📖 API Reference\n\nRun `moon doc --serve` to view the API documentation.\n\n## 📜 License\n\nThis project is licensed under the Apache License 2.0. See [LICENSE](https://github.com/ShellWen/lru-cache-mbt/blob/master/LICENSE) for details.\n\n## 📢 Contact \u0026 Support\n\n- Author: ShellWen Chen \u003cme@shellwen.com\u003e\n- GitHub Issues: [Report an issue](https://github.com/ShellWen/lru-cache-mbt/issues)\n\n👋 If you like this project, give it a ⭐! Happy coding! 🚀\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshellwen%2Flru-cache-mbt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshellwen%2Flru-cache-mbt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshellwen%2Flru-cache-mbt/lists"}