UNPKG

simple-node-memory-cache

Version:

In-memory object cache written in typescript for Node that supports multiple eviction strategies.

71 lines (70 loc) 2.45 kB
"use strict"; var __values = (this && this.__values) || function (o) { var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; if (m) return m.call(o); return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var e_1, _a; Object.defineProperty(exports, "__esModule", { value: true }); var index_1 = require("./strategies/index"); var cache1 = new index_1.SimpleLFU(); // function sleep(milliseconds) { // var start = new Date().getTime(); // for (var i = 0; i < 1e7; i++) { // if ((new Date().getTime() - start) > milliseconds){ // break; // } // } // } for (var i = 0; i < 1; i++) { cache1.set('key1', 'value1'); cache1.set('key2', 'value2'); cache1.set('key3', 'value3'); cache1.set('key4', 'value4'); cache1.set('key5', 'value5'); cache1.set('key6', 'removes 1'); console.log("GET KEY2: " + cache1.get('key2')); console.log("GET KEY3: " + cache1.get('key3')); console.log("GET KEY3: " + cache1.get('key3')); console.log("GET KEY4: " + cache1.get('key4')); console.log("GET KEY5: " + cache1.get('key5')); console.log("GET KEY6: " + cache1.get('key6')); cache1.set('key7', 'removes 3'); console.log('#############################################'); try { for (var _b = (e_1 = void 0, __values(cache1.entries())), _c = _b.next(); !_c.done; _c = _b.next()) { var _d = __read(_c.value, 2), key = _d[0], value = _d[1]; console.log(key + " => " + value); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_1) throw e_1.error; } } console.log('#############################################'); cache1.clear(); }