Without further ado, here are some common apis for handling applets’ local data caches, with local caches up to 10M:

1. Data storage:

Wx.setstorage ({key:'city', data:'sz'}) // Synchronize wx.setStoragesync ('key','value')Copy the code

2. Data acquisition: Obtain the contents of the specified key from the local cache

Wx.getstorage ({key:'city', success(res){console.log(res.data)}})Copy the code

Obtain storage information // keys All the keys in the current storage // Current space occupied by the unit of KB // Limited space size, unit of KB

wx.getStorageInfo({ success(res){ console.log(res.keys) console.log(res.currentSize) console.log(res.limitSize) } }) // synchronize const res = wx.getStorageInfosync () console.log(res.keys) console.log(res.currentsize) console.log(res.limitsize)Copy the code

4. Delete data: Remove the specified key from the local cache

wx.removeStorage({
    key:'key',
    success(res){
        console.log(res)
    }
})

wx.removeStorageSync('key')
Copy the code

5. Data clearing: clear the local data cache

Wx.clearstorage () // Asynchronous wx.clearStoragesync () // SynchronousCopy the code