# Data Cache / Storage
# setStorageSync
Supported since Base Library 1.3.9, iOS SDK 2.1.23, Android SDK 2.1.38
setStorageSync(string key, any data)
Synchronous version of ft.setStorage
Parameters
- string key: The specified key in the local cache
- any data: The content to be stored. Only supports native types, Date, and objects that can be serialized via JSON.stringify.
Sample Code
ft.setStorage({
key: 'key',
data: 'value'
})
try {
ft.setStorageSync('key', 'value')
} catch (e) { }
# setStorage
Supported since Base Library 1.3.9, iOS SDK 2.1.23, Android SDK 2.1.38
setStorage(Object object)
Stores data in the specified key in the local cache. This will overwrite the original content corresponding to that key. The data storage lifecycle is consistent with the Mini-Program itself, meaning the data remains available unless the user actively deletes it or it is automatically cleaned up after a certain period. The maximum storage limit for all data is 10MB.
Parameters
Object object
| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| key | string | Yes | The specified key in the local cache | |
| data | any | Yes | The content to be stored. Only supports native types, Date, and objects that can be serialized via JSON.stringify. | |
| success | function | No | Callback function for successful API call | |
| fail | function | No | Callback function for failed API call | |
| complete | function | No | Callback function for the end of the API call (executed regardless of success or failure) |
Sample Code
ft.setStorage({
key: 'key',
data: 'value'
})
try {
ft.setStorageSync('key', 'value')
} catch (e) { }
# removeStorageSync
Supported since Base Library 1.3.9, iOS SDK 2.1.23, Android SDK 2.1.38
removeStorageSync(string key)
Synchronous version of ft.removeStorage
Sample Code
ft.removeStorage({
key: 'key',
success(res) {
console.log(res)
}
})
try {
ft.removeStorageSync('key')
} catch (e) {
// Do something when catch error
}
# removeStorage
Supported since Base Library 1.3.9, iOS SDK 2.1.23, Android SDK 2.1.38
removeStorage(Object object)
Asynchronously removes the content corresponding to the specified key from the local cache.
Parameters
Object object
| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| key | string | Yes | The specified key in the local cache | |
| success | function | No | Callback function for successful API call | |
| fail | function | No | Callback function for failed API call | |
| complete | function | No | Callback function for the end of the API call (executed regardless of success or failure) |
Sample Code
ft.removeStorage({
key: 'key',
success(res) {
console.log(res)
}
})
try {
ft.removeStorageSync('key')
} catch (e) {
// Do something when catch error
}
# getStorageSync
Supported since Base Library 1.3.9, iOS SDK 2.1.23, Android SDK 2.1.38
getStorageSync(string key)
Synchronous version of ft.getStorage
Parameters
string key: The specified key in the local cache
Return Value
any data: The content corresponding to the key
Sample Code
ft.getStorage({
key: 'key',
success(res) {
console.log(res.data)
}
})
try {
const value = ft.getStorageSync('key')
if (value) {
// Do something with return value
}
} catch (e) {
// Do something when catch error
}
# getStorageInfoSync
Supported since Base Library 1.3.9, iOS SDK 2.1.23, Android SDK 2.1.38
getStorageInfoSync(Object object)
Synchronous version of ft.getStorageInfo
Return Value
Object object
| Property | Type | Description |
|---|---|---|
| keys | Array.<string> | All keys in the current storage |
| currentSize | number | The currently occupied space size, in KB |
| limitSize | number | The limited space size, in KB |
Sample Code
ft.getStorageInfoSync({
success(res) {
console.log(res.keys)
console.log(res.currentSize)
console.log(res.limitSize)
}
})
try {
const res = ft.getStorageInfoSync()
console.log(res.keys)
console.log(res.currentSize)
console.log(res.limitSize)
} catch (e) {
// Do something when catch error
}
# getStorageInfo
Supported since Base Library 1.3.9, iOS SDK 2.1.23, Android SDK 2.1.38
getStorageInfo(Object object)
Gets the relevant information of the current storage.
Parameters
Object object
| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| success | function | No | Callback function for successful API call | |
| fail | function | No | Callback function for failed API call | |
| complete | function | No | Callback function for the end of the API call (executed regardless of success or failure) |
object.success Callback Function
Parameters
Object res
| Property | Type | Description |
|---|---|---|
| keys | Array.<string> | All keys in the current storage |
| currentSize | number | The currently occupied space size, in KB |
| limitSize | number | The limited space size, in KB |
Sample Code
ft.getStorageInfo({
success(res) {
console.log(res.keys)
console.log(res.currentSize)
console.log(res.limitSize)
}
})
try {
const res = ft.getStorageInfoSync()
console.log(res.keys)
console.log(res.currentSize)
console.log(res.limitSize)
} catch (e) {
// Do something when catch error
}
# getStorage
Supported since Base Library 1.3.9, iOS SDK 2.1.23, Android SDK 2.1.38
getStorage(Object object)
Gets the content corresponding to the specified key from the local cache.
Parameters
Object object
| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| key | string | Yes | The specified key in the local cache | |
| success | function | No | Callback function for successful API call | |
| fail | function | No | Callback function for failed API call | |
| complete | function | No | Callback function for the end of the API call (executed regardless of success or failure) |
object.success Callback Function
Parameters
Object res
| Property | Type | Description |
|---|---|---|
| data | any | The content corresponding to the key |
Sample Code
ft.getStorage({
key: 'key',
success(res) {
console.log(res.data)
}
})
try {
const value = ft.getStorageSync('key')
if (value) {
// Do something with return value
}
} catch (e) {
// Do something when catch error
}
# clearStorageSync
Supported since Base Library 1.3.9, iOS SDK 2.1.23, Android SDK 2.1.38
clearStorageSync(Object object)
Synchronous version of ft.clearStorage
Sample Code
ft.clearStorage()
try {
ft.clearStorageSync()
} catch (e) {
// Do something when catch error
}
# clearStorage
Supported since Base Library 1.3.9, iOS SDK 2.1.23, Android SDK 2.1.38
clearStorage(Object object)
Clears the local data cache.
Parameters
Object object
| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| success | function | No | Callback function for successful API call | |
| fail | function | No | Callback function for failed API call | |
| complete | function | No | Callback function for the end of the API call (executed regardless of success or failure) |
Sample Code
ft.clearStorage()
try {
ft.clearStorageSync()
} catch (e) {
// Do something when catch error
}