本地?cái)?shù)據(jù)緩存

2020-02-12 16:40 更新

小程序可以通過(guò)下面列出的 API 讀取、寫(xiě)入、刪除、清理本地緩存數(shù)據(jù)。與LocalStorage類似。

本地緩存數(shù)據(jù)以用戶+小程序緯度隔離,同一臺(tái)設(shè)備上,不同用戶之間、不同小程序之間,本地緩存 數(shù)據(jù)不可互訪。

?? 注意本地緩存數(shù)據(jù)的上限約為10MB,同時(shí)也受到用戶設(shè)備存儲(chǔ)空間、緩存清理等機(jī)制的限制,可能會(huì)導(dǎo)致信息丟失。因此請(qǐng)不要將重要數(shù)據(jù)存放在本地?cái)?shù)據(jù)緩存


API Checklist

  • getStorage
  • getStorageSync
  • setStorage
  • setStorageSync
  • removeStorage
  • removeStorageSync
  • clearStorage
  • clearStorageSync
  • getStorageInfo
  • getStorageInfoSync


本地緩存數(shù)據(jù)類型

小程序默認(rèn)支持以下數(shù)據(jù)類型,存儲(chǔ)和獲取時(shí)無(wú)需類型轉(zhuǎn)換。其它數(shù)據(jù)類型可根據(jù)需要在處理時(shí)轉(zhuǎn)換為字符串存儲(chǔ),強(qiáng)行操作會(huì)導(dǎo)致數(shù)據(jù)丟失。

  • String
  • Object
  • Array
  • Number
  • Date
  • Boolean
  • Undefined
  • Null
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)