async function user(){
let cache = user.cache || (user.cache = new Map())
//判断函数中是否存在
if(user.cache.has(name)){
return await user.cache.get(name)
}
// 存储数据
user.cache.set(name,'数据1')
return 'Hello word'
}
setTimeout(_=>{
user('cache').then(res=>{console.log(res)})
},1000)
//第一次执行打印结果 Hello word
setTimeout(_=>{
user('cache').then(res=>{console.log(res)})
},1000)
//第二次执行打印结果 '数据1'