class h{constructor(e="cache_",t=10*60*1e3){this.prefix=e,this.duration=t}generateKey(e={}){const a=Object.keys(e).sort().map(r=>`${r}:${e[r]??"none"}`).join("_");return`${this.prefix}${a}`}save(e,t){try{const a={data:t,timestamp:Date.now(),expiry:Date.now()+this.duration};localStorage.setItem(e,JSON.stringify(a))}catch(a){console.warn("Failed to save to cache:",a)}}load(e){try{const t=localStorage.getItem(e);if(!t)return null;const a=JSON.parse(t);return Date.now()>a.expiry?(localStorage.removeItem(e),null):a.data}catch(t){return console.warn("Failed to load from cache:",t),null}}remove(e){try{localStorage.removeItem(e)}catch(t){console.warn("Failed to remove cache:",t)}}clearAll(){try{Object.keys(localStorage).forEach(t=>{t.startsWith(this.prefix)&&localStorage.removeItem(t)})}catch(e){console.warn("Failed to clear all caches:",e)}}clearExpired(){try{const e=Object.keys(localStorage),t=Date.now();e.forEach(a=>{if(a.startsWith(this.prefix))try{const r=JSON.parse(localStorage.getItem(a));r&&t>r.expiry&&localStorage.removeItem(a)}catch{localStorage.removeItem(a)}})}catch(e){console.warn("Failed to clear expired caches:",e)}}has(e){return this.load(e)!==null}getStats(){try{const t=Object.keys(localStorage).filter(c=>c.startsWith(this.prefix)),a=Date.now();let r=0,o=0,n=0;return t.forEach(c=>{try{const l=localStorage.getItem(c);n+=l.length;const i=JSON.parse(l);a>i.expiry?o++:r++}catch{o++}}),{total:t.length,valid:r,expired:o,size:`${(n/1024).toFixed(2)} KB`}}catch(e){return console.warn("Failed to get cache stats:",e),{total:0,valid:0,expired:0,size:"0 KB"}}}}function g(s,e){return new h(`${s}_cache_`,e)}export{g as c};
