codecamp

字节跳动小程序开发API 本地数据缓存

小程序可以通过下面列出的API读取、写入、删除、清理本地缓存数据。与LocalStorage类似。

本地缓存数据以用户+小程序纬度隔离,同一台设备上,不同用户之间、不同小程序之间,本地缓存数据不可互访。

⚠️注意

本地缓存数据的上限约为10MB,同时也受到用户设备存储空间、缓存清理等机制的限制,可能会导致信息丢失。因此请不要将重要数据存放在本地数据缓存

API Checklist


本地缓存数据类型


小程序默认支持以下数据类型,存储和获取时无需类型转换。其它数据类型可根据需要在处理时转换为字符串存储,强行操作会导致数据丢失。

  • String
  • Object
  • Array
  • Number
  • Date
  • Boolean
  • Undefined
  • Null


温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

字节跳动小程序 介绍

字节跳动小程序 开发

字节跳动小程序开发框架

字节跳动小程序开发框架基础说明

字节跳动小程序开发框架基础功能

字节跳动小程序开发框架逻辑层

无标题文章

无标题目录

API

无标题文章

无标题文章

无标题文章

无标题文章

无标题文章

无标题目录

无标题目录

无标题文章

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }