tencent cloud

Feedback

Data Caching

Last updated: 2024-03-04 23:11:05

    setStorage

    This API is used via wx.setStorage(Object object).
    Feature Description: Stores data in the specified key within the local cache, overwriting any existing content associated with that key. The data remains available unless the user actively deletes it or it is cleared by the system due to storage space constraints. The maximum data length allowed for a single key is 1 MB, with an overall data storage limit of 10 MB.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    key
    string
    -
    Yes
    Specified key in the local cache
    data
    any
    -
    Yes
    The content that needs to be stored. Only native types, Date, and objects that can be serialized through JSON.stringify are supported.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    wx.setStorage({
    key:"key",
    data:"value"
    })
    wx.setStorage({
    key: 'key',
    success (res) {
    console.log(res.data)
    }
    })

    setStorageSync

    This API is used via wx.setStorageSync(string key, any data).
    Note:
    Storage should be used solely for persistent data storage, and not for runtime data transmission or global state management. Excessive synchronous read-write operations during the startup process can significantly increase the duration of startup time.
    Feature Description: Stores data in the specified key within the local cache, overwriting any existing content associated with that key. The data remains available unless the user actively deletes it or it is cleared by the system due to storage space constraints. The maximum data length allowed for a single key is 1 MB, with an overall data storage limit of 10 MB.
    Parameter and Description: string key, the specified key in local storage; any data, the content to be stored. Only supports native types, Date, and objects that can be serialized through JSON.stringify.
    Sample Code
    try {
    wx.setStorageSync('key', 'value')
    } catch (e) { }

    revokeBufferURL

    This API is used via wx.revokeBufferURL(string url)
    Function description: Destroy the data stored in memory according to the URL.
    Parameters and description: string url, the binary data URL that needs to be destroyed.

    removeStorage

    This API is used via wx.removeStorage(Object object).
    Feature Description: Removes the specified key from local storage.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    key
    string
    -
    Yes
    Specified key in the local cache
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    wx.removeStorage({
    key: 'key',
    success (res) {
    console.log(res)
    }
    })
    try {
    wx.removeStorageSync('key')
    } catch(e) {
    // Do something when catch error
    }

    removeStorageSync

    This API is used via wx.removeStorageSync(string key).
    Feature Description: The synced version of wx.removeStorage.
    Parameter and Description: string key, specified key in the local cache.
    Sample Code
    wx.removeStorage({
    key: 'key',
    success (res) {
    console.log(res)
    }
    })
    try {
    wx.removeStorageSync('key')
    } catch(e) {
    // Do something when catch error
    }

    getStorage

    This API is used via wx.getStorage(Object object).
    Feature Description: Asynchronously gets the content of the specified key from local storage.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    key
    string
    -
    Yes
    Specified key in the local cache
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    data
    any
    The content corresponding to the key.
    Sample Code
    wx.getStorage({
    key: 'key',
    success (res) {
    console.log(res.data)
    }
    })
    wx.getStorage({
    key: 'key',
    success (res) {
    console.log(res.data)
    }
    })

    createBufferURL

    This API is used via string wx.createBufferURL(ArrayBuffer|TypedArray buffer)
    Function description: Create a unique URL based on the incoming buffer and store it in memory.
    Parameters and description: ArrayBuffer|TypedArray buffer, binary data that needs to be stored in memory.
    Return value: string.

    getStorageSync

    This API is used via any wx.getStorageSync(string key).
    Feature Description: Synchronously gets the content of the specified key from local storage.
    Parameter and Description: string key, specified key in the local cache.
    Return Value: Any key, corresponding content.
    Sample Code
    try {
    var value = wx.getStorageSync('key')
    if (value) {
    // Do something with return value
    }
    } catch(e) {
    // Do something when catch error
    }

    getStorageInfo

    This API is used via wx.getStorageInfo(Object object).
    Feature Description: Asynchronously obtains relevant information about the current storage.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object.
    Attribute
    Type
    Description
    keys
    Array.<string>
    All keys in the current storage.
    currentSize
    number
    Current occupied space size, in kilobytes (KB).
    limitSize
    number
    Restricted space size, in kilobytes (KB).
    Sample Code
    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 used via Object wx.getStorageInfoSync().
    Function Description: The synced version of wx.getStorageInfo.
    Return Value: Object.
    Attribute
    Type
    Description
    keys
    Array.
    All keys in the current storage.
    currentSize
    number
    Current occupied space size, in kilobytes (KB).
    limitSize
    number
    Restricted space size, in kilobytes (KB).
    Sample Code
    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 used via wx.clearStorage(Object object).
    Feature Description: Clears local data cache.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    wx.clearStorage()
    try {
    wx.clearStorageSync()
    } catch(e) {
    // Do something when catch error
    }

    clearStorageSync

    This API is used via wx.clearStorageSync().
    Function Description: The synced version of wx.clearStorage.
    Sample Code
    wx.clearStorage()
    try {
    wx.clearStorageSync()
    } catch(e) {
    // Do something when catch error
    }

    batchSetStorage

    This API is used via wx.batchSetStorage(Object object).
    Feature Description: Batch stores data in the specified key within the local cache, overwriting any existing content associated with that key. The data remains available unless the user actively deletes it or it is cleared by the system due to storage space constraints. The maximum data length allowed for a single key is 1 MB, with an overall data storage limit of 10 MB.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    kvList
    Array
    -
    Yes
    [{ key, value }]
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    wx.setStorage({
    key:"key",
    data:"value"
    })
    // Enable encrypted storage
    wx.batchSetStorage({
    kvList: [{
    key: 'key',
    value: 'value',
    }],
    })

    batchSetStorageSync

    This API is used via Array.<any> wx.batchGetStorageSync(Array.<string> keyList).
    Feature Description: Batch stores data in the specified key within the local cache, overwriting any existing content associated with that key. The data remains available unless the user actively deletes it or it is cleared by the system due to storage space constraints. The maximum data length allowed for a single key is 1 MB, with an overall data storage limit of 10 MB.
    Parameters and Description: Array.<Object> kvList.
    Attribute
    Type
    Default value
    Required
    Description
    key
    string
    -
    Yes
    Key: Specified key in the local cache.
    value
    any
    -
    Yes
    The content that needs to be stored. Only native types, Date, and objects that can be serialized through JSON.stringify are supported.
    Sample Code
    try {
    wx.batchSetStorageSync([{key: 'key', value: 'value'}])
    } catch (e) { }

    batchGetStorage

    This API is used via wx.batchGetStorage(Object object).
    Feature Description: Asynchronously batch gets the content of the specified key from local storage.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    keyList
    Array.<string>
    -
    Yes
    Specified keyList in the local cache
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    wx.batchGetStorage({
    keyList: ['key'],
    success (res) {
    console.log(res)
    }
    })

    batchGetStorageSync

    This API is used via Array.<any> wx.batchGetStorageSync(Array.<string> keyList).
    Feature Description: Synchronously batch gets the content of the specified key from the local cache.
    Parameter Description: Array.<string> keyList, specified array of keys in local cache.
    Return value: Array.<any>, corresponding content of the key.
    Sample Code
    // For reading multiple keys, batch reading is superior in performance to multiple getStorageSync readings.
    try {
    var valueList = wx.batchGetStorageSync(['key'])
    if (valueList) {
    // Do something with return value
    }
    } catch (e) {
    // Do something when catch error
    }
    
    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 avaliable.

    7x24 Phone Support