/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define((function(){"use strict";return function(){function t(t=15e3,e=5e3){this._timer=null,this._cachedBlocks=new Map,this._size=-1,this._duration=t,this._interval=Math.min(t,e)}var e=t.prototype;return e.decreaseRefCount=function(t,e){const i=t+"/"+e,n=this._cachedBlocks;if(n.has(i)){const t=n.get(i);return t.refCount--,t.refCount<=0&&(n.delete(i),t.controller&&t.controller.abort()),t.refCount}return 0},e.getBlock=function(t,e){const i=t+"/"+e,n=this._cachedBlocks;if(n.has(i)){const t=n.get(i);return t.ts=Date.now(),t.refCount++,n.delete(i),n.set(i,t),t.block}return null},e.putBlock=function(t,e,i,n=null){const s=this._cachedBlocks,r=t+"/"+e;if(s.has(r)){const t=s.get(r);t.ts=Date.now(),t.refCount++}else s.set(r,{block:i,ts:Date.now(),refCount:1,controller:n});this._trim(),this._updateTimer()},e.deleteBlock=function(t,e){const i=this._cachedBlocks,n=t+"/"+e;i.has(n)&&i.delete(n)},e.updateMaxSize=function(t){this._size=t,this._trim()},e.empty=function(){this._cachedBlocks.clear(),this._clearTimer()},e.getCurrentSize=function(){return this._cachedBlocks.size},e._updateTimer=function(){if(null!=this._timer)return;const t=this._cachedBlocks;this._timer=setInterval((()=>{const e=Array.from(t),i=Date.now();for(let n=0;n<e.length&&e[n][1].ts<=i-this._duration;n++)t.delete(e[n][0]);0===t.size&&this._clearTimer()}),this._interval)},e._trim=function(){const t=this._cachedBlocks;if(-1===this._size||this._size>=t.size)return;const e=Array.from(t);for(let i=0;i<e.length-this._size;i++)t.delete(e[i][0])},e._clearTimer=function(){null!=this._timer&&(clearInterval(this._timer),this._timer=null)},t}()}));
