UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 1.23 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import e from"./Logger.js";import{RemoveMode as c,NoPriority as t}from"./MemCache.js";const h=()=>e.getLogger("esri/core/MemCachePool");class r{constructor(e,t){this._cache=e(t,((e,t,r)=>{switch(t){case c.ALL:return e.forEach((e=>e.dispose())),0;case c.SOME:{const c=e.shift();return c?(r-=Math.round(c.cachedMemory),c.dispose()):r>0&&(h().warn("Encountered empty MemCachePool with non-zero memory."),r=0),r}}}))}hitrate(){return this._cache.hitRate}destroy(){this._cache.destroy()}clear(){this._cache.clear()}getSize(e){return this._cache.getSize(e)}pop(e){const c=this._cache.peek(e);if(!c)return;const t=c.pop();return c.length>0?t&&(c.cachedMemory=this._cache.getSize(e)-Math.round(t.cachedMemory),this._cache.updateSize(e,c)):this._cache.pop(e),t}put(e,c,h=t){const r=this._cache.peek(e);if(r)r.push(c),r.cachedMemory=this._cache.getSize(e)+Math.round(c.cachedMemory),this._cache.updateSize(e,r);else{const t=new s(c);this._cache.put(e,t,h)}}}class s extends Array{constructor(e){super(),this.item=e,this.cachedMemory=e.cachedMemory,this.push(e)}}export{r as MemCachePool};