{"_id":"@3-/lru","_rev":"3-27dcf5a604e2ab9e55301e58a5e67be1","name":"@3-/lru","dist-tags":{"latest":"0.1.32"},"versions":{"0.1.30":{"name":"@3-/lru","version":"0.1.30","keywords":["cache","lru","lhd","eviction","size-aware","wasm"],"author":{"name":"i18n.site@gmail.com"},"license":"MulanPSL-2.0","_id":"@3-/lru@0.1.30","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://github.com/js0-site/rust/tree/dev/size_lru","bugs":{"url":"https://github.com/js0-site/rust/issues"},"dist":{"shasum":"cab0e88afd7d74a5db2ec5dec51ff01832aa1126","tarball":"https://registry.npmjs.org/@3-/lru/-/lru-0.1.30.tgz","fileCount":5,"integrity":"sha512-bW3u9rUJ/mpVGdYXhfbTLerMIGTd9m6sCoAgv7Urs5e1Dxr8F9YJvbwLpXaAsw76NL9Y0tzImcgHhotvT/qaXg==","signatures":[{"sig":"MEYCIQDtdEZEsp8HNfQiPTw36eOLozIz6IYThjjFZRhEbdK0OAIhANTy8usrMr2UxBrAqxLJfxMfaLHiKUwIb4skcY5ULgh9","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":65412},"main":"index.js","type":"module","types":"index.d.ts","gitHead":"15d8a58b122618f60bc1916524a6b06f2dcd6c80","_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://github.com/js0-site/rust.git","type":"git"},"_npmVersion":"11.13.0","description":"Fastest size-aware LRU cache with highest hit rate via LHD algorithm / 最快的大小感知 LRU 缓存，基于 LHD 算法实现最高命中率","directories":{},"_nodeVersion":"26.2.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/lru_0.1.30_1779960805328_0.051177217778179296","host":"s3://npm-registry-packages-npm-production"}},"0.1.31":{"name":"@3-/lru","version":"0.1.31","keywords":["cache","lru","lhd","eviction","size-aware","wasm"],"author":{"name":"i18n.site@gmail.com"},"license":"MulanPSL-2.0","_id":"@3-/lru@0.1.31","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://github.com/js0-site/rust/tree/dev/size_lru","bugs":{"url":"https://github.com/js0-site/rust/issues"},"dist":{"shasum":"b6359b7fa533c92615ac82214d2999b0c09fd718","tarball":"https://registry.npmjs.org/@3-/lru/-/lru-0.1.31.tgz","fileCount":5,"integrity":"sha512-MMFwMaqamQ9E6PCzlJgsm0tT/YKoS1fx6FeKifW11eK29lJxSzwAPLmVKl+yRaF4UtCK/2gEUbhZd49OLctMPw==","signatures":[{"sig":"MEQCIFrXXdMtqk3SXpnTGaHDN8eJul7HiTKgDhD5A/t1PDDfAiBC42PxkJ+YHG/gy7ilPuqXa0VeQ9PVjp/1jQO4+g5jKA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":65412},"main":"index.js","type":"module","types":"index.d.ts","gitHead":"07490908c854e20599f230a84257f03fd5f945eb","_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://github.com/js0-site/rust.git","type":"git"},"_npmVersion":"11.13.0","description":"Fastest size-aware LRU cache with highest hit rate via LHD algorithm / 最快的大小感知 LRU 缓存，基于 LHD 算法实现最高命中率","directories":{},"_nodeVersion":"26.2.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/lru_0.1.31_1779960847975_0.5162624167327785","host":"s3://npm-registry-packages-npm-production"}},"0.1.32":{"name":"@3-/lru","version":"0.1.32","description":"Fastest size-aware LRU cache with highest hit rate via LHD algorithm / 最快的大小感知 LRU 缓存，基于 LHD 算法实现最高命中率","keywords":["cache","lru","lhd","eviction","size-aware","wasm"],"homepage":"https://github.com/js0-site/rust/tree/dev/size_lru","license":"MulanPSL-2.0","author":{"name":"i18n.site@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/js0-site/rust.git"},"type":"module","main":"index.js","types":"index.d.ts","gitHead":"f11cf0dd4cc710339c16dbd764432dd5219686f1","_id":"@3-/lru@0.1.32","bugs":{"url":"https://github.com/js0-site/rust/issues"},"_nodeVersion":"26.2.0","_npmVersion":"11.13.0","dist":{"integrity":"sha512-SXOXvWjtHyjyVS4FCjwb4IgUT42CNrj4I4+k97oMAHEQ2UsdyAs8OWScJzen9WRvljqbLcN8iN4BqQJfMB/XaA==","shasum":"e7345c3cbf5c60ec6de7e4a08983ca43e717003c","tarball":"https://registry.npmjs.org/@3-/lru/-/lru-0.1.32.tgz","fileCount":5,"unpackedSize":51055,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCJnBnsoOoXdGGb67bf4dwu9v3yBNL3GCneMUlK/M8clQIgF84EiFwiFayJLEwPSIgPn9A8tuITaZvuIRY3SFK51EQ="}]},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"directories":{},"maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/lru_0.1.32_1779962016612_0.18490725287329446"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-28T09:33:25.135Z","modified":"2026-05-28T09:53:36.874Z","0.1.30":"2026-05-28T09:33:25.468Z","0.1.31":"2026-05-28T09:34:08.113Z","0.1.32":"2026-05-28T09:53:36.761Z"},"bugs":{"url":"https://github.com/js0-site/rust/issues"},"author":{"name":"i18n.site@gmail.com"},"license":"MulanPSL-2.0","homepage":"https://github.com/js0-site/rust/tree/dev/size_lru","keywords":["cache","lru","lhd","eviction","size-aware","wasm"],"repository":{"type":"git","url":"git+https://github.com/js0-site/rust.git"},"description":"Fastest size-aware LRU cache with highest hit rate via LHD algorithm / 最快的大小感知 LRU 缓存，基于 LHD 算法实现最高命中率","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"readme":"[English](#en) | [中文](#zh)\n\n---\n\n<a id=\"en\"></a>\n\n# @3-/lru : Fastest Size-Aware LRU Cache (Wasm)\n\nInstall the package via Bun:\n\n```bash\nbun i @3-/lru\n```\n\n## Usage Example\n\n```javascript\nimport init, { WasmCache } from \"@3-/lru\";\n\n// Initialize the WebAssembly module\nawait init();\n\n// Initialize cache and binary items\nconst cache = new WasmCache(250),\n  bin_a = new Uint8Array([1, 2, 3, 4]),\n  bin_b = new Uint8Array([5, 6, 7, 8]);\ncache.set(\"a\", bin_a, bin_a.length); // size = 4 + 96 = 100\ncache.set(\"b\", bin_b, bin_b.length); // size = 4 + 96 = 100\n\n// Retrieve cached items\nconsole.log(\"Get a:\", cache.get(\"a\"));\nconsole.log(\"Get b:\", cache.get(\"b\"));\n\n// Insert an item that triggers eviction of 'a' (100 + 100 + 100 = 300 > 250)\nconst bin_c = new Uint8Array([9, 10, 11, 12]);\ncache.set(\"c\", bin_c, bin_c.length); // size = 4 + 96 = 100\n\n// Verify eviction of 'a' and retention of 'b' and 'c'\nconsole.log(\"Get a after eviction:\", cache.get(\"a\")); // undefined\nconsole.log(\"Get b after eviction:\", cache.get(\"b\")); // Uint8Array\n```\n\n## Eviction Callback\n\nYou can provide an optional eviction callback function when instantiating `WasmCache`. The callback will be triggered synchronously with the evicted key and value:\n\n```javascript\nconst cacheWithCallback = new WasmCache(250, (key, value) => {\n  console.log(`Evicted: key=\"${key}\", value=`, value);\n});\n\ncacheWithCallback.set(\"a\", bin_a, bin_a.length);\ncacheWithCallback.set(\"b\", bin_b, bin_b.length);\n\n// Trigger eviction\ncacheWithCallback.set(\"c\", bin_c, bin_c.length);\n```\n\n---\n\nUnderlying Rust Crate: [size_lru](https://crates.io/crates/size_lru)\n\n---\n\n<a id=\"zh\"></a>\n\n# @3-/lru : 最快的大小感知 LRU 缓存 (Wasm)\n\n通过 Bun 安装：\n\n```bash\nbun i @3-/lru\n```\n\n## 使用演示\n\n```javascript\nimport init, { WasmCache } from \"@3-/lru\";\n\n// 初始化 WebAssembly 模块\nawait init();\n\n// 初始化缓存并写入二进制数据\nconst cache = new WasmCache(250),\n  bin_a = new Uint8Array([1, 2, 3, 4]),\n  bin_b = new Uint8Array([5, 6, 7, 8]);\ncache.set(\"a\", bin_a, bin_a.length); // 实际大小 = 4 + 96 = 100\ncache.set(\"b\", bin_b, bin_b.length); // 实际大小 = 4 + 96 = 100\n\n// 获取缓存数据\nconsole.log(\"获取 a:\", cache.get(\"a\"));\nconsole.log(\"获取 b:\", cache.get(\"b\"));\n\n// 插入新数据触发淘汰（300 > 250，因为之后访问了 'b'，'a' 最久未被访问将被淘汰）\nconst bin_c = new Uint8Array([9, 10, 11, 12]);\ncache.set(\"c\", bin_c, bin_c.length); // 实际大小 = 4 + 96 = 100\n\n// 验证淘汰结果\nconsole.log(\"淘汰后获取 a:\", cache.get(\"a\")); // undefined\nconsole.log(\"淘汰后获取 b:\", cache.get(\"b\")); // Uint8Array\n```\n\n## 淘汰回调\n\n你可以在实例化 `WasmCache` 时传入一个可选的回调函数。当有条目被淘汰时，该函数会被同步触发，并传入被淘汰的键和值：\n\n```javascript\nconst cacheWithCallback = new WasmCache(250, (key, value) => {\n  console.log(`条目被淘汰: 键=\"${key}\", 值=`, value);\n});\n\ncacheWithCallback.set(\"a\", bin_a, bin_a.length);\ncacheWithCallback.set(\"b\", bin_b, bin_b.length);\n\n// 插入新数据触发淘汰\ncacheWithCallback.set(\"c\", bin_c, bin_c.length);\n```\n\n---\n\n底层 Rust Crate: [size_lru](https://crates.io/crates/size_lru)\n","readmeFilename":"README.md"}