UNPKG

@nutui/nutui-react

Version:

京东风格的轻量级移动端 React 组件库,支持一套代码生成 H5 和小程序

50 lines (49 loc) 1.62 kB
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _create_class } from "@swc/helpers/_/_create_class"; import { _ as _define_property } from "@swc/helpers/_/_define_property"; var MiniLru = /*#__PURE__*/ function() { "use strict"; function MiniLru(capacity) { _class_call_check(this, MiniLru); _define_property(this, "cache", void 0); _define_property(this, "capacity", void 0); if (capacity <= 0) { throw new Error('Cache capacity must be a positive number'); } this.cache = new Map(); this.capacity = capacity; } _create_class(MiniLru, [ { key: "get", value: function get(key) { if (this.cache.has(key)) { var value = this.cache.get(key); this.cache.delete(key); this.cache.set(key, value); return value; } return null; } }, { key: "set", value: function set(key, value) { if (this.cache.has(key)) { this.cache.delete(key); } else if (this.cache.size >= this.capacity) { this.cache.delete(this.cache.keys().next().value); } this.cache.set(key, value); } }, { key: "has", value: function has(key) { return this.cache.has(key); } } ]); return MiniLru; }(); export { MiniLru as default };