tencent cloud

All product documents
Tencent Cloud Super App as a Service
Data Cache
Last updated: 2025-04-10 18:18:34
Data Cache
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
}


Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon