UNPKG

@nutui/nutui-react

Version:

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

59 lines (58 loc) 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "MiniLru", { enumerable: true, get: function() { return MiniLru; } }); var _class_call_check = require("@swc/helpers/_/_class_call_check"); var _create_class = require("@swc/helpers/_/_create_class"); var _define_property = require("@swc/helpers/_/_define_property"); var MiniLru = /*#__PURE__*/ function() { "use strict"; function MiniLru(capacity) { (0, _class_call_check._)(this, MiniLru); (0, _define_property._)(this, "cache", void 0); (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; } (0, _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; }();