tencent cloud

Tencent Cloud Super App as a Service

Release Notes and Announcements
Announcement: Tencent Cloud Mini Program Platform Renamed to Tencent Cloud Super App as a Service on January 2, 2025
Console Updates
Android SDK Updates
iOS SDK Updates
Flutter SDK Updates
IDE Updates
Base Library Updates
Product Introduction
Overview
Strengths
Use Cases
Purchase Guide
Billing Overview
Pay-As-You-Go Billing
Renewal Guide
Service Suspension Instructions
Getting Started
Plan Management
Overview
Console Account Management
Storage Configuration
Acceleration Configuration
Branding Configurations
Platform Features
Console Login
Users and Permission System
Mini Program Management
Mini Game Management
Superapp Management
Commercialization
Platform Management
User Management
Team Management
Operations Management
Security Center
Code Integration Guide
Getting Demo and SDK
Android
iOS
Flutter
Superapp Server
GUID Generation Rules
Mini Program Development Guide
Mini Program Introduction and Development Environment
Mini Program Code Composition
Guide
Framework
Components
API
Server Backend
JS SDK
Base Library
IDE Operation Instructions
Mini Game Development Guide
Guide
API
Server Backend
Practice Tutorial
Mini Program Login Practical Tutorial
Mini Program Subscription Message Practical Tutorial
Payment Practical Tutorial
Ad Integration Practical Tutorial
Mini Game Subscription Message Practical Tutorial
API Documentation
History
Introduction
API Category
Making API Requests
Operation Management APIs
User Management APIs
Team Management APIs
Sensitive API-Related APIs
Role Management APIs
Platform Management APIs
Other Console APIs
Mini Program or Mini Game APIs
Management-Sensitive APIs
Global Domain Management APIs
Superapp APIs
Data Types
Agreements
Service Level Agreement
Data Processing and Security Agreement
SDK Privacy Policy Module
SDK Data Processing and Security Agreement Module

Data Cache

PDF
Focus Mode
Font Size
Last updated: 2025-04-10 18:18:34

setStorage

This API is called using wx.setStorage(Object object).
Feature description:Stores the data in local cache under the specified key, which will overwrite the original content associated with that key. The data is always available unless the user deletes it or the system cleans it up to free up storage space. The maximum size of data that can be stored in a single key is 1 MB, and the upper storage limit for all data is 10 MB.
Parameter and description: Object object.
Property
Type
Default value
‍Required
Description
key
string
-
True
The key specified in the local cache.
data
any
-
True
The content that needs to be stored. Only objects of native types, dates, and objects that can be serialized viaJSON.stringify are supported.
success
function
-
False
Callback function for successful API calls.
fail
function
-
False
Callback function for failed API calls.
complete
function
-
False
Callback function executed after API call ends (regardless of success or failure).
Example:
wx.setStorage({
key:"key",
data:"value"
})
wx.setStorage({
key: 'key',
success (res) {
console.log(res.data)
}
})

setStorageSync

This API is called using wx.setStorageSync(string key, any data).
Note:
Storage should only be used for persistent storage of data, not for runtime data transfer or global state management. Excessive synchronous read/write operations during the startup process can significantly impact startup time.
Feature description:Stores the data in local cache under the specified key, which will overwrite the original content associated with that key. The data is always available unless the user deletes it or the system cleans it up to free up storage space. The maximum size of data that can be stored in a single key is 1 MB, and the upper storage limit for all data is 10 MB.
Parameters and description: string key, the key specified in the local cache;any data, content to be stored. Only objects of native types, dates, and objects that can be serialized via JSON.stringify are supported.
Example:
try {
wx.setStorageSync('key', 'value')
} catch (e) { }

revokeBufferURL

Note:
This API is supported in mini programs but not in mini games.
This API is called using wx.revokeBufferURL(string url).
Feature description:Destroys the data in memory associated with the specified URL.
Parameter and description: string url. The URL of the binary data that needs to be destroyed.

removeStorage

This API is called using wx.removeStorage(Object object).
Feature description:Removes the specified key from the local cache.
Parameter and description: Object object.
Property
Type
Default value
‍Required
Description
key
string
-
True
The key specified in the local cache.
success
function
-
False
Callback function for successful API calls.
fail
function
-
False
Callback function for failed API calls.
complete
function
-
False
Callback function executed after API call ends (regardless of success or failure).
Example:
wx.removeStorage({
key: 'key',
success (res) {
console.log(res)
}
})
try {
wx.removeStorageSync('key')
} catch (e) {
// Do something when catch error
}

removeStorageSync

This API is called using wx.removeStorageSync(string key).
Feature description:Synchronously performs the same feature as wx.removeStorage..
Parameter and description:string key. The key specified in the local cache.
Example:
wx.removeStorage({
key: 'key',
success (res) {
console.log(res)
}
})
try {
wx.removeStorageSync('key')
} catch (e) {
// Do something when catch error
}

getStorage

This API is called using wx.getStorage(Object object).
Feature description:Asynchronously gets the content of the specified key from the local cache.
Parameter and description: Object object.
Property
Type
Default value
‍Required
Description
key
string
-
True
The key specified in the local cache.
success
function
-
False
Callback function for successful API calls.
fail
function
-
False
Callback function for failed API calls.
complete
function
-
False
Callback function executed after API call ends (regardless of success or failure).
Object.success callback function parameter:Object res.
Property
Type
Description
data
any
The content corresponding to the key.
Example:
wx.getStorage({
key: 'key',
success (res) {
console.log(res.data)
}
})
wx.getStorage({
key: 'key',
success (res) {
console.log(res.data)
}
})

createBufferURL

Note:
This API is supported in mini programs but not in mini games.
This API is called using string wx.createBufferURL(ArrayBuffer|TypedArray buffer).
Feature description:Creates a unique URL in memory based on the provided buffer.
Parameter and description:ArrayBuffer|TypedArray buffer. The binary data to be stored in memory.
Return value:string.

getStorageSync

This API is called using any wx.getStorageSync(string key).
Note:
Storage should only be used for persistent storage of data, not for runtime data transfer or global state management. Excessive synchronous read/write operations during the startup process can significantly impact startup time.
Feature description:Synchronously gets the content of the specified key from the local cache.
Parameter and description: string key. The key specified in the local cache.
Return value: any key. The content corresponding to the key.
Example:
try {
var value = wx.getStorageSync('key')
if (value) {
// Do something with return value
}
} catch (e) {
// Do something when catch error
}

getStorageInfo

This API is called using wx.getStorageInfo(Object object).
Feature description:Asynchronously gets the information of the current storage.
Parameter and description: Object object.
Property
Type
Default value
‍Required
Description
success
function
-
False
Callback function for successful API calls.
fail
function
-
False
Callback function for failed API calls.
complete
function
-
False
Callback function executed after API call ends (regardless of success or failure).
object.success callback function parameter: Object object.
Property
Type
Description
keys
Array.<string>
All keys in the current storage.
currentSize
number
Currently used space size in KB.
limitSize
number
Limited space size in KB.
Example:
wx.getStorageInfo({
success(res) {
console.log(res.keys)
console.log(res.currentSize)
console.log(res.limitSize)
}
})
wx.getStorageInfo({
success(res) {
console.log(res.keys)
console.log(res.currentSize)
console.log(res.limitSize)
}
})

getStorageInfoSync

This API is called using Object wx.getStorageInfoSync().
Feature description:Synchronously performs the same feature as wx.getStorageInfo.
Return value:Object object.
Property
Type
Description
keys
Array.
All keys in the current storage.
currentSize
number
Currently used space size in KB.
limitSize
number
Limited space size in KB.
Example:
wx.getStorageInfo({
success (res) {
console.log(res.keys)
console.log(res.currentSize)
console.log(res.limitSize)
}
})
try {
const res = wx.getStorageInfoSync()
console.log(res.keys)
console.log(res.currentSize)
console.log(res.limitSize)
} catch (e) {
// Do something when catch error
}

clearStorage

This API is called using wx.clearStorage(Object object).
Feature description:Clears the local data cache.
Parameter and description:Object object.
Property
Type
Default value
‍Required
Description
success
function
-
False
Callback function for successful API calls.
fail
function
-
False
Callback function for failed API calls.
complete
function
-
False
Callback function executed after API call ends (regardless of success or failure).
Example:
wx.clearStorage()
try {
wx.clearStorageSync()
} catch(e) {
// Do something when catch error
}

clearStorageSync

This API is called using wx.clearStorageSync().
Feature description:Synchronously performs the same feature as wx.clearStorage.
Example:
wx.clearStorage()
try {
wx.clearStorageSync()
} catch(e) {
// Do something when catch error
}

batchSetStorage

This API is called using wx.batchSetStorage(Object object).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Stores the data in batches to the specified key in the local cache, which will overwrite the original content associated with that key. The data is always available unless the user deletes it or the system cleans it up to free up storage space. The maximum size of data that can be stored in a single key is 1 MB, and the upper storage limit for all data is 10 MB.
Parameter and description:Object object
Property
Type
Default value
‍Required
Description
kvList
Array
-
True
[{ key, value }]
success
function
-
False
Callback function for successful API calls.
fail
function
-
False
Callback function for failed API calls.
complete
function
-
False
Callback function executed after API call ends (regardless of success or failure).
Array.<Object> kvList
Property
Type
Default value
‍Required
Description
key
string

True
The key specified in the local cache.
value
any

True
The content that needs to be stored. Only objects of native types, dates, and objects that can be serialized via JSON.stringify are supported.
Example:
wx.setStorage({
key:"key",
data:"value"
})
// Enable encrypted storage
wx.batchSetStorage({
kvList: [{
key: 'key',
value: 'value',
}],
})

batchSetStorageSync

This API is called using Array.<any> wx.batchGetStorageSync(Array.<string> keyList).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Stores the data in batches to the specified key in the local cache, which will overwrite the original content associated with that key. The data is always available unless the user deletes it or the system cleans it up to free up storage space. The maximum size of data that can be stored in a single key is 1 MB, and the upper storage limit for all data is 10 MB.
Parameter and description:Array.<Object> kvList。
Property
Type
Default value
‍Required
Description
key
string
-
True
The key specified in the local cache.
value
any
-
True
The content that needs to be stored. Only objects of native types, dates, and objects that can be serialized via JSON.stringify are supported.
Example:
try {
wx.batchSetStorageSync([{key: 'key', value: 'value'}])
} catch (e) { }

batchGetStorage

This API is called using wx.batchGetStorage(Object object).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Asynchronously gets the content of the specified key in batches from the local cache.
Parameter and description:Object object.
Property
Type
Default value
‍Required
Description
keyList
Array.<string>
-
True
The keyList specified in the local cache.
success
function
-
False
Callback function for successful API calls.
fail
function
-
False
Callback function for failed API calls.
complete
function
-
False
Callback function executed after API call ends (regardless of success or failure).
Example:
wx.batchGetStorage({
keyList: ['key'],
success (res) {
console.log(res)
}
})

batchGetStorageSync

This API is called using Array.<any> wx.batchGetStorageSync(Array.<string> keyList).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Synchronously gets the content of the specified key in batches from the local cache.
Parameter and description:Array.<string> keyList. An array of specified keys in the local cache.
Return value:Array.<any>. The content corresponding to the key.
Example:
//Batch reading is more efficient than multiple getStorageSync calls when retrieving multiple keys
try {
var valueList = wx.batchGetStorageSync(['key'])
if (valueList) {
// Do something with return value
}
} catch (e) {
// Do something when catch error
}



Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback