import{useRef as e,useEffect as r,useCallback as t}from"react";import{cancelIdleWork as n}from"../cache-utils/idle-callback.js";import{CACHE_TTL as c,STORAGE_KEY as a}from"./constants.js";import{useTileCacheHydration as l}from"./useTileCacheHydration.js";import{createTileCacheFlusher as u}from"./createTileCacheFlusher.js";var i=function(){var i=e(new Map),o=e(new Map),s=e(new Set);l(i,s);var m=e(u({pendingWritesRef:o,idleHandlesRef:s}));return r((function(){var e=m.current,r=s.current;return function(){e.cancel(),r.forEach(n),r.clear()}}),[]),{getCachedTile:t((function(e){var r=Date.now(),t=i.current.get(e);if(t&&r-t.timestamp<c)return t.wellIds;var n=o.current.get(e);return n&&r-n.timestamp<c?n.wellIds:(t&&i.current.delete(e),null)}),[]),setCachedTile:t((function(e,r){var t={wellIds:r,timestamp:Date.now()};i.current.set(e,t),o.current.set(e,t),m.current()}),[]),clearCache:t((function(){i.current.clear(),o.current.clear(),m.current.cancel(),s.current.forEach(n),s.current.clear(),sessionStorage.removeItem(a)}),[])}};export{i as useTileCache};
//# sourceMappingURL=useTileCache.js.map
