@luband/jstools
Version:
前端工具包
2 lines (1 loc) • 864 B
JavaScript
import{__extends as t}from"tslib";import{BaseCache as e}from"./baseCache.js";var r=new(function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.storage=localStorage,t}return t(r,e),r.prototype.setItem=function(t,r,i,o){if(o){var s=this.getItem("lb-expireKeys",!0)||[];(null==s?void 0:s.includes(t))||(s.push(t),this.setItem("lb-expireKeys",s,!0)),r={data:r,time:Date.now(),expires:o}}e.prototype.setItem.call(this,t,r,!!o||i)},r.prototype.getItem=function(t,r){var i=e.prototype.getItem.call(this,"lb-expireKeys",!0);if(null==i?void 0:i.includes(t)){var o=e.prototype.getItem.call(this,t,!0),s=o.data;if(o.time+o.expires<Date.now()){this.removeItem(t);var l=i.findIndex((function(e){return e===t}));return i.splice(l,1),this.setItem("lb-expireKeys",i,!0),null}return s}return e.prototype.getItem.call(this,t,r)},r}(e));export{r as default};