SOURCE

const cacheStorage = {
    time: '',
    setItme(key, value, time) {
        const obj = {
            data: value,
            time
        }
        localStorage.setItem(key, JSON.stringify(obj))
    },
    getItem(key) {
        const data = JSON.parse(localStorage.getItem(key));
        if (!data) return null;
        if (data.time) {
            const saveTime = new Date(data.time).getTime()
            const nowTime = new Date().getTime()

            if (nowTime > saveTime) {
                localStorage.removeItem(key)
                return null
            }
        }
        return data
    }
}

cacheStorage.setItme('z', 'zzz', '2022-02-13')

console.log(cacheStorage.getItem('z'))
console 命令行工具 X clear

                    
>
console