<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          StorageLRULRU 緩存實(shí)現(xiàn)

          聯(lián)合創(chuàng)作 · 2023-09-29 06:05

          StorageLRU(storage-lru) 是 LRU 緩存實(shí)現(xiàn),可以用在本地存儲或者其他存儲機(jī)制,支持一個類似的接口。

          注意:這個庫是使用 CommonJS 風(fēng)格編寫的,如果要在瀏覽器使用,需要使用 BrowserifyWebpack 類似的工具。

          主要特性:

          • 可插拔的離線存儲

          • 統(tǒng)計(jì)數(shù)據(jù)

          • 自定義的 PurgeComparator

          • 優(yōu)先級

          • 自動清理

          使用:

          var StorageLRU = require('storage-lru').StorageLRU;
          var asyncify = require('storage-lru').asyncify;
          var lru = new StorageLRU(asyncify(localStorage), {
              purgeFactor: 0.5,  // this controls amount of extra space to purge.
              purgedFn: function (purgedKeys) {
                  console.log('These keys were purged:', purgedKeys);
              }
          });
          console.log(lru.numItems()); // output 0, assuming the storage is clear
          lru.setItem('foo', 'bar', {}, function (err) {
              if (err) {
                  // something went wrong. Item not saved.
                  console.log('Failed to save item: err=', err);
              }
          });
          lru.setItem('fooJSON', {foo: 'bar'}, {json: true}, function (err) {
              if (err) {
                  // something went wrong. Item not saved.
                  console.log('Failed to save item: err=', err);
              }
          });
          lru.getItem('foo', {json: false}, function (err, value) {
              if (err) {
                  // something went wrong, for example, can't deserialize
                  console.log('Failed to fetch item: err=', err);
                  return;
              }
              console.log('The value of "foo" is: ', value);
          });
          lru.removeItem('foo', function (err) {
              if (err) {
                  // something went wrong. Item not removed.
              }
          });
          var stats = lru.stats();
          瀏覽 27
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  中文字幕在线观看网 | 国产级A片 | 曰批免费视频 | 中文字幕久久成人 | 人人干人人插 |