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AW,GACT,IAEF,OAAO,IACT,EAEA,KAAK,KAAO,WACV,OAAO,CACT,EAEA,KAAK,QAAU,WACb,IACE,EADE,EAAO,EAEX,IAAK,KAAO,EACV,IAEF,OAAO,CACT,EAEA,KAAK,MAAQ,SAAS,GACpB,EAAS,CACX,EAEA,KAAK,KAAO,WACV,OAAO,CACT,EAEA,KAAK,OAAS,WACZ,OAAO,CACT,EAEA,KAAK,KAAO,WACV,OAAO,OAAO,KAAK,EACrB,EAEA,KAAK,WAAa,WAChB,IAAI,EAAe,CAAC,EAIpB,IAAK,IAAI,KAAO,EAAQ,CACtB,IAAI,EAAS,EAAO,GACpB,EAAa,GAAO,CAClB,MAAO,EAAO,MACd,OAAQ,EAAO,QAAU,MAE7B,CAEA,OAAO,KAAK,UAAU,EACxB,EAEA,KAAK,WAAa,SAAS,EAAc,GACvC,IAAI,EAAgB,KAAK,MAAM,GAC3B,EAAW,KAAK,MAEhB,EAAiB,GAAW,EAAQ,eAExC,IAAK,IAAI,KAAO,EACd,GAAI,EAAc,eAAe,GAAM,CACrC,GAAI,EAEF,GADqB,EAAO,GACR,CACd,GACF,QAAQ,IAAI,uCAA0C,GAExD,QACF,CAGF,IAAI,EAAS,EAAc,GAIvB,EAAgB,EAAO,OAAS,EAEpC,GAAI,GAAiB,EAAG,CAEtB,KAAK,IAAI,GACT,QACF,CAIA,EAAgB,EAAgB,EAAI,OAAgB,EAEpD,KAAK,IAAI,EAAK,EAAO,MAAO,EAC9B,CAGF,OAAO,KAAK,MACd,CACF,CAEA,OAAO,QAAU,IAAI,MACrB,OAAO,QAAQ,MAAQ","file":"/npm/memory-cache@0.2.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/memory-cache@0.2.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nfunction Cache () {\n  var _cache = Object.create(null);\n  var _hitCount = 0;\n  var _missCount = 0;\n  var _size = 0;\n  var _debug = false;\n\n  this.put = function(key, value, time, timeoutCallback) {\n    if (_debug) {\n      console.log('caching: %s = %j (@%s)', key, value, time);\n    }\n\n    if (typeof time !== 'undefined' && (typeof time !== 'number' || isNaN(time) || time <= 0)) {\n      throw new Error('Cache timeout must be a positive number');\n    } else if (typeof timeoutCallback !== 'undefined' && typeof timeoutCallback !== 'function') {\n      throw new Error('Cache timeout callback must be a function');\n    }\n\n    var oldRecord = _cache[key];\n    if (oldRecord) {\n      clearTimeout(oldRecord.timeout);\n    } else {\n      _size++;\n    }\n\n    var record = {\n      value: value,\n      expire: time + Date.now()\n    };\n\n    if (!isNaN(record.expire)) {\n      record.timeout = setTimeout(function() {\n        _del(key);\n        if (timeoutCallback) {\n          timeoutCallback(key, value);\n        }\n      }.bind(this), time);\n    }\n\n    _cache[key] = record;\n\n    return value;\n  };\n\n  this.del = function(key) {\n    var canDelete = true;\n\n    var oldRecord = _cache[key];\n    if (oldRecord) {\n      clearTimeout(oldRecord.timeout);\n      if (!isNaN(oldRecord.expire) && oldRecord.expire < Date.now()) {\n        canDelete = false;\n      }\n    } else {\n      canDelete = false;\n    }\n\n    if (canDelete) {\n      _del(key);\n    }\n\n    return canDelete;\n  };\n\n  function _del(key){\n    _size--;\n    delete _cache[key];\n  }\n\n  this.clear = function() {\n    for (var key in _cache) {\n      clearTimeout(_cache[key].timeout);\n    }\n    _size = 0;\n    _cache = Object.create(null);\n    if (_debug) {\n      _hitCount = 0;\n      _missCount = 0;\n    }\n  };\n\n  this.get = function(key) {\n    var data = _cache[key];\n    if (typeof data != \"undefined\") {\n      if (isNaN(data.expire) || data.expire >= Date.now()) {\n        if (_debug) _hitCount++;\n        return data.value;\n      } else {\n        // free some space\n        if (_debug) _missCount++;\n        _size--;\n        delete _cache[key];\n      }\n    } else if (_debug) {\n      _missCount++;\n    }\n    return null;\n  };\n\n  this.size = function() {\n    return _size;\n  };\n\n  this.memsize = function() {\n    var size = 0,\n      key;\n    for (key in _cache) {\n      size++;\n    }\n    return size;\n  };\n\n  this.debug = function(bool) {\n    _debug = bool;\n  };\n\n  this.hits = function() {\n    return _hitCount;\n  };\n\n  this.misses = function() {\n    return _missCount;\n  };\n\n  this.keys = function() {\n    return Object.keys(_cache);\n  };\n\n  this.exportJson = function() {\n    var plainJsCache = {};\n\n    // Discard the `timeout` property.\n    // Note: JSON doesn't support `NaN`, so convert it to `'NaN'`.\n    for (var key in _cache) {\n      var record = _cache[key];\n      plainJsCache[key] = {\n        value: record.value,\n        expire: record.expire || 'NaN',\n      };\n    }\n\n    return JSON.stringify(plainJsCache);\n  };\n\n  this.importJson = function(jsonToImport, options) {\n    var cacheToImport = JSON.parse(jsonToImport);\n    var currTime = Date.now();\n\n    var skipDuplicates = options && options.skipDuplicates;\n\n    for (var key in cacheToImport) {\n      if (cacheToImport.hasOwnProperty(key)) {\n        if (skipDuplicates) {\n          var existingRecord = _cache[key];\n          if (existingRecord) {\n            if (_debug) {\n              console.log('Skipping duplicate imported key \\'%s\\'', key);\n            }\n            continue;\n          }\n        }\n\n        var record = cacheToImport[key];\n\n        // record.expire could be `'NaN'` if no expiry was set.\n        // Try to subtract from it; a string minus a number is `NaN`, which is perfectly fine here.\n        var remainingTime = record.expire - currTime;\n\n        if (remainingTime <= 0) {\n          // Delete any record that might exist with the same key, since this key is expired.\n          this.del(key);\n          continue;\n        }\n\n        // Remaining time must now be either positive or `NaN`,\n        // but `put` will throw an error if we try to give it `NaN`.\n        remainingTime = remainingTime > 0 ? remainingTime : undefined;\n\n        this.put(key, record.value, remainingTime);\n      }\n    }\n\n    return this.size();\n  };\n}\n\nmodule.exports = new Cache();\nmodule.exports.Cache = Cache;\n"]}