Data Storage
Offers key-value local storage APIs for caching game data on the device, supporting both asynchronous and synchronous operations for setting, getting, removing, and clearing stored data.
TTMinis.game.setStorage(opts)
Stores data in the local cache. If the key already exists, updates its corresponding value.
Parameters
Field | Type | Description | Required |
|
| The specified key in the local cache | Yes |
|
| The content to store. Only supports native types, | Yes |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
Example
TTMinis.game.setStorage({
key: "gameLocalData",
data: {
a: 1,
b: 2,
c: 3
},
success: () => {
// Do something when succeed
},
fail: (error) => {
// Do something when failed
},
complete: () => {
// Do something when completed
}
})TTMinis.game.setStorageSync(key, data)
Synchronously stores data in the local cache at the specified key. Overwrites the previous content associated with the key.
Parameters
Field | Type | Description | Required |
|
| The specified key in the local cache | Yes |
|
| The content to store. Only supports native types, | Yes |
Example
try {
TTMinis.game.setStorageSync('key', 'value')
} catch (e) {
// Handle error
}TTMinis.game.getStorage(opts)
Asynchronously retrieves the content of the specified key from the local cache.
Parameters
Field | Type | Description | Required |
|
| The specified key in the local cache | Yes |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
The success callback receives a result object with the following field:
Field | Type | Description |
|
| The content associated with the key |
Example
TTMinis.game.getStorage({
key: 'key',
success(res) {
console.log(res.data)
}
})TTMinis.game.getStorageSync(key)
Synchronously retrieves the content of the specified key from the local cache.
Parameters
Field | Type | Description | Required |
|
| The specified key in the local cache | Yes |
Returns
any - The content associated with the key.
Example
try {
var value = TTMinis.game.getStorageSync('key')
if (value) {
// Do something with the return value
}
} catch (e) {
// Handle error
}TTMinis.game.removeStorage(opts)
Removes the specified key from the local cache.
Parameters
Field | Type | Description | Required |
|
| The specified key in the local cache | Yes |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
Example
TTMinis.game.removeStorage({
key: 'key',
success(res) {
console.log(res)
}
})TTMinis.game.removeStorageSync(key)
Synchronously removes the specified key from the local cache.
Parameters
Field | Type | Description | Required |
|
| The specified key in the local cache | Yes |
Example
try {
TTMinis.game.removeStorageSync('key')
} catch (e) {
// Handle error
}TTMinis.game.clearStorage(opts)
Clears the local data cache.
Parameters
Field | Type | Description | Required |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
Example
TTMinis.game.clearStorage()TTMinis.game.clearStorageSync()
Synchronously clears the local data cache.
Example
try {
TTMinis.game.clearStorageSync()
} catch (e) {
// Handle error
}TTMinis.game.getStorageInfo(opts)
Asynchronously gets information about the current storage.
Note: Supported starting from SDK version 0.8.0. Lower versions must be adjusted for compatibility.
Parameters
Field | Type | Description | Required |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
The success callback receives a result object with the following fields:
Field | Type | Description |
|
| All keys in the current storage |
|
| The current space usage in KB |
|
| The storage space limit in KB |
Example
TTMinis.game.getStorageInfo({
success(res) {
console.log(res.keys)
console.log(res.currentSize)
console.log(res.limitSize)
}
})TTMinis.game.getStorageInfoSync()
Synchronously gets information about the current storage.
Note: Supported starting from SDK version 0.8.0. Lower versions must be adjusted for compatibility.
Returns
Object with the following fields:
Field | Type | Description |
|
| All keys in the current storage |
|
| The current space usage in KB |
|
| The storage space limit in KB |
Example
try {
const res = TTMinis.game.getStorageInfoSync()
console.log(res.keys)
console.log(res.currentSize)
console.log(res.limitSize)
} catch (e) {
// Handle error
}