UNPKG

847 BJavaScriptView Raw
1import{objectSpread2 as e}from"./_virtual/_rollupPluginBabelHelpers.js";import t from"react";import{subscribe as c,getSnapshot as o,setKey as a,setTTL as r,setPeriodTime as n,setPeriodically as i,add as l,has as u,get as f,clear as y}from"./garbage.js";var p={key:"",ttl:3600,periodTime:6e4,periodically:!1},d=function(d){var k=e(e({},p),d),m=t.useSyncExternalStore(c,o);t.useEffect((function(){var e;(e=k).key&&(a(e.key),r(e.ttl),n(e.periodTime),i(e.periodically))}),[]);return{cache:m,has:function(e){return u("".concat(k.key,"._").concat(e))},add:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;t=t?"".concat(k.key,"._").concat(t):"".concat(k.key,"._").concat(k.key),l(e,t)},clear:function(e){y("".concat(k.key,"._").concat(e))},get:function(e){return f("".concat(k.key,"._").concat(e))}}};export{d as default};