Lightweight storage provides applications with data processing capability and allows applications to perform lightweight data storage and query. Data is stored in key-value (KV) pairs. Keys are of the string type, and values can be of the number, string, or Boolean type.
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```
import data_Preferences from '@ohos.data.preferences'
Removes the singleton **Preferences** instance of the specified file from the memory, and deletes the specified file, its backup file, and corrupted files. After the specified files are deleted, the **Preferences** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This method uses an asynchronous callback to return the execution result.
Removes the singleton **Preferences** instance of the specified file from the memory, and deletes the specified file, its backup file, and corrupted files. After the specified files are deleted, the **Preferences** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This method uses a promise to return the execution result.
Removes the singleton **Preferences** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur.
This method uses an asynchronous callback to return the result.
Removes the singleton **Preferences** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur.
This method uses an asynchronous callback to return the result.
Obtains the **Preferences** instance corresponding to the specified file, writes data to the **Preferences** instance using a **Preferences** API, and saves data to the file using **flush()** or **flushSync()**.
This method uses an asynchronous callback to return the result.
Obtains the **Preferences** instance corresponding to the specified file, writes data to the **Preferences** instance using a **Preferences** API, and saves data to the file using **flush()** or **flushSync()**.
This method uses an asynchronous callback to return the result.
Lightweight storage provides applications with data processing capability and allows applications to perform lightweight data storage and query. Data is stored in key-value pairs. Keys are of the string type, and values can be of the numeric, string, or Boolean type.
Lightweight storage provides applications with data processing capability and allows applications to perform lightweight data storage and query. Data is stored in key-value (KV) pairs. Keys are of the string type, and values can be of the number, string, or Boolean type.
>The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import<a name="s56d19203690d4782bfc74069abb6bd71"></a>
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. <br/>The APIs of this module are no longer maintained since API Version 9. You are advised to use [@ohos.data.preferences](js-apis-data-preferences.md).
<tdclass="cellrowborder"valign="top"width="44.519999999999996%"headers="mcps1.1.6.1.5 "><pid="p12478654172415"><aname="p12478654172415"></a><aname="p12478654172415"></a>Maximum length of a key. It is 80 bytes.</p>
<tdclass="cellrowborder"valign="top"width="44.519999999999996%"headers="mcps1.1.6.1.5 "><pid="p1470645211154"><aname="p1470645211154"></a><aname="p1470645211154"></a>Maximum length of a value of the string type. It is 8192 bytes.</p>
<td class="cellrowborder" valign="top" width="49.614822038030226%" headers="mcps1.1.5.1.4 "><p id="p989815213187"><a name="p989815213187"></a><a name="p989815213187"></a>Callback used to return the result.</p>
</td>
</tr>
</tbody>
</table>
- Example:
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| path | string | Yes| Path of the target file.|
| callback | AsyncCallback<[Storage](#storage)> | Yes| Callback used to return the execution result.|
- Example
```
import dataStorage from '@ohos.data.storage'
import featureAbility from '@ohos.ability.featureAbility'
(async () => {
var context = featureAbility.getContext()
var path = await context.getFilesDir()
dataStorage.getStorage(path + '/mystore', function (err, storage) {
...
...
@@ -177,158 +83,78 @@ Reads a specified file and loads the data to the **Storage** instance for data
<td class="cellrowborder" valign="top" width="69.56%" headers="mcps1.1.3.1.2 "><p id="p1062005172514"><a name="p1062005172514"></a><a name="p1062005172514"></a>Promise used to return the result.</p>
</td>
</tr>
</tbody>
</table>
- Example:
- Return value
| Type| Description|
| -------- | -------- |
| Promise<[Storage](#storage)> | Promise used to return the result.|
- Example
```
import dataStorage from '@ohos.data.storage'
import featureAbility from '@ohos.ability.featureAbility'
(async () => {
var context = featureAbility.getContext()
var path = await context.getFilesDir()
let promise = dataStorage.getStorage(path + '/mystore')
promise.then((storage) => {
let promisegetSt = dataStorage.getStorage(path + '/mystore')
promisegetSt.then((storage) => {
storage.putSync('startup', 'auto')
storage.flushSync()
}).catch((err) => {
console.info("Get the storage failed, path: " + path + '/mystore')
Removes the singleton **Storage** instance of the specified file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified file is deleted, the **Storage** instance cannot be used to perform any data operation. Otherwise, data inconsistency will occur. This method uses a synchronous mode.
Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This method uses a synchronous mode.
Removes the singleton **Storage** instance of the specified file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified file is deleted, the **Storage** instance cannot be used to perform any data operation. Otherwise, data inconsistency will occur. This method uses an asynchronous callback to return the execution result.
Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This method uses an asynchronous callback to return the execution result.
<td class="cellrowborder" valign="top" width="54.39297903461725%" headers="mcps1.1.5.1.4 "><p id="p396915388374"><a name="p396915388374"></a><a name="p396915388374"></a>Callback used to return the result.</p>
</td>
</tr>
</tbody>
</table>
- Example:
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| path | string | Yes| Path of the target file.|
| callback | AsyncCallback<void> | Yes| Callback used to return the execution result.|
- Example
```
dataStorage.deleteStorage(path + '/mystore', function (err) {
if (err) {
...
...
@@ -340,59 +166,28 @@ Removes the singleton **Storage** instance of the specified file from the memo
Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This method uses a promise to return the execution result.
Removes the singleton **Storage** instance of the specified file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified file is deleted, the **Storage** instance cannot be used to perform any data operation. Otherwise, data inconsistency will occur. This method uses a promise to return the execution result.
<td class="cellrowborder" valign="top" width="82.99%" headers="mcps1.1.3.1.2 "><p id="p15446536474"><a name="p15446536474"></a><a name="p15446536474"></a>Promise used to return the result.</p>
</td>
</tr>
</tbody>
</table>
- Example:
- Return value
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
- Example
```
let promise = dataStorage.deleteStorage(path + '/mystore')
promise.then(() => {
let promisedelSt = dataStorage.deleteStorage(path + '/mystore')
promisedelSt.then(() => {
console.info("Deleted successfully.")
}).catch((err) => {
console.info("Deleted failed with err: " + err)
...
...
@@ -400,90 +195,44 @@ Removes the singleton **Storage** instance of the specified file from the memo
Removes the singleton **Storage** instance of the specified file from the memory. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur.
Removes the singleton **Storage** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur.
Removes the singleton **Storage** instance of the specified file from the memory. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur.
Removes the singleton **Storage** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur.
This method uses an asynchronous mode.
This method uses an asynchronous callback to return the result.
<td class="cellrowborder" valign="top" width="52.58898098488542%" headers="mcps1.1.5.1.4 "><p id="p191301575425"><a name="p191301575425"></a><a name="p191301575425"></a>Callback used to return the result.</p>
</td>
</tr>
</tbody>
</table>
- Example:
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| path | string | Yes| Path of the target file.|
| callback | AsyncCallback<void> | Yes| Callback used to return the execution result.|
- Example
```
dataStorage.removeStorageFromCache(path + '/mystore', function (err) {
if (err) {
...
...
@@ -495,61 +244,30 @@ This method uses an asynchronous mode.
Removes the singleton **Storage** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur.
Removes the singleton **Storage** instance of the specified file from the memory. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur.
This method uses an asynchronous callback to return the result.
<td class="cellrowborder" valign="top" width="82.99%" headers="mcps1.1.3.1.2 "><p id="p13941645472"><a name="p13941645472"></a><a name="p13941645472"></a>Promise used to return the result.</p>
</td>
</tr>
</tbody>
</table>
- Example:
- Return value
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
- Example
```
let promise = dataStorage.removeStorageFromCache(path + '/mystore')
promise.then(() => {
let promiserevSt = dataStorage.removeStorageFromCache(path + '/mystore')
promiserevSt.then(() => {
console.info("Removed storage from cache successfully.")
}).catch((err) => {
console.info("Removed storage from cache failed with err: " + err)
...
...
@@ -557,130 +275,57 @@ This method uses an asynchronous mode.
```
## Storage<a name="section12882825611"></a>
## Storage
Provides APIs for obtaining and modifying storage data.
| key | string | Yes| Key of the data. It cannot be empty.|
| defValue | ValueType | Yes| Default value to be returned if the value of the specified key does not exist. It can be a number, string, or Boolean value.|
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p10404192513199"><a name="p10404192513199"></a><a name="p10404192513199"></a>Key of the data. It cannot be empty.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p1140502514190"><a name="p1140502514190"></a><a name="p1140502514190"></a>Default value to be returned if the value of the specified key does not exist. The value can be a number, string, or Boolean value.</p>
<td class="cellrowborder" valign="top" width="82.99%" headers="mcps1.1.3.1.2 "><p id="p1832294181917"><a name="p1832294181917"></a><a name="p1832294181917"></a>Value corresponding to the specified key. If the value is null or not in the default value format, the default value is returned.</p>
</td>
</tr>
</tbody>
</table>
- Example:
- Return value
| Type| Description|
| -------- | -------- |
| ValueType | Value corresponding to the specified key. If the value is null or not in the default value format, the default value is returned.|
<td class="cellrowborder" valign="top" width="59.76596782057533%" headers="mcps1.1.5.1.4 "><p id="p793710294206"><a name="p793710294206"></a><a name="p793710294206"></a>Key of the data. It cannot be empty.</p>
<td class="cellrowborder" valign="top" width="59.76596782057533%" headers="mcps1.1.5.1.4 "><p id="p129372299204"><a name="p129372299204"></a><a name="p129372299204"></a>Default value to be returned. The value can be a number, string, or Boolean value.</p>
<td class="cellrowborder" valign="top" width="59.76596782057533%" headers="mcps1.1.5.1.4 "><p id="p893812912201"><a name="p893812912201"></a><a name="p893812912201"></a>Callback used to return the result.</p>
</td>
</tr>
</tbody>
</table>
- Example:
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the data. It cannot be empty.|
| defValue | ValueType | Yes| Default value to be returned. It can be a number, string, or Boolean value.|
| callback | AsyncCallback<ValueType> | Yes| Callback used to return the execution result.|
<td class="cellrowborder" valign="top" width="59.76596782057533%" headers="mcps1.1.5.1.4 "><p id="p717812534216"><a name="p717812534216"></a><a name="p717812534216"></a>Key of the data. It cannot be empty.</p>
<td class="cellrowborder" valign="top" width="59.76596782057533%" headers="mcps1.1.5.1.4 "><p id="p817813533210"><a name="p817813533210"></a><a name="p817813533210"></a>Default value to be returned. The value can be a number, string, or Boolean value.</p>
<td class="cellrowborder" valign="top" width="70.41%" headers="mcps1.1.3.1.2 "><p id="p15633101522214"><a name="p15633101522214"></a><a name="p15633101522214"></a>Promise used to return the result.</p>
</td>
</tr>
</tbody>
</table>
- Example:
- Return value
| Type| Description|
| -------- | -------- |
| Promise<ValueType> | Promise used to return the result.|
- Example
```
let promise = storage.get('startup', 'default')
promise.then((value) => {
let promiseget = storage.get('startup', 'default')
promiseget.then((value) => {
console.info("The value of startup is " + value)
}).catch((err) => {
console.info("Get the value of startup failed with err: " + err)
...
...
@@ -763,108 +369,46 @@ This method uses an asynchronous mode.
```
### putSync<a name="section2042914810266"></a>
### putSync
putSync\(key: string, value: ValueType\): void
putSync(key: string, value: ValueType): void
Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush\(\)** or **flushSync\(\)**.
Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush()** or **flushSync()**.
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p6628521122615"><a name="p6628521122615"></a><a name="p6628521122615"></a>Key of the data to be modified. It cannot be empty.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p15628721142612"><a name="p15628721142612"></a><a name="p15628721142612"></a>New value. The value can be a number, string, or Boolean value.</p>
</td>
</tr>
</tbody>
</table>
- Example:
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the data to modify. It cannot be empty.|
| value | ValueType | Yes| New value to store. It can be a number, string, or Boolean value.|
Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush\(\)** or **flushSync\(\)**.
Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush()** or **flushSync()**.
This method uses an asynchronous mode.
This method uses an asynchronous callback to return the result.
<td class="cellrowborder" valign="top" width="51.55533885909311%" headers="mcps1.1.5.1.4 "><p id="p775614662815"><a name="p775614662815"></a><a name="p775614662815"></a>Key of the data to be modified. It cannot be empty.</p>
<td class="cellrowborder" valign="top" width="51.55533885909311%" headers="mcps1.1.5.1.4 "><p id="p117561246192811"><a name="p117561246192811"></a><a name="p117561246192811"></a>New value. The value can be a number, string, or Boolean value.</p>
<td class="cellrowborder" valign="top" width="51.55533885909311%" headers="mcps1.1.5.1.4 "><p id="p375610463287"><a name="p375610463287"></a><a name="p375610463287"></a>Callback used to return the result.</p>
</td>
</tr>
</tbody>
</table>
- Example:
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the data to modify. It cannot be empty.|
| value | ValueType | Yes| New value to store. It can be a number, string, or Boolean value.|
| callback | AsyncCallback<void> | Yes| Callback used to return the execution result.|
- Example
```
storage.put('startup', 'auto', function (err) {
if (err) {
...
...
@@ -876,70 +420,31 @@ This method uses an asynchronous mode.
Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush()** or **flushSync()**.
Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush\(\)** or **flushSync\(\)**.
This method uses an asynchronous callback to return the result.
<td class="cellrowborder" valign="top" width="59.76596782057533%" headers="mcps1.1.5.1.4 "><p id="p144354963019"><a name="p144354963019"></a><a name="p144354963019"></a>Key of the data to be modified. It cannot be empty.</p>
<td class="cellrowborder" valign="top" width="59.76596782057533%" headers="mcps1.1.5.1.4 "><p id="p17435149123016"><a name="p17435149123016"></a><a name="p17435149123016"></a>New value. The value can be a number, string, or Boolean value.</p>
<td class="cellrowborder" valign="top" width="82.99%" headers="mcps1.1.3.1.2 "><p id="p208781523143017"><a name="p208781523143017"></a><a name="p208781523143017"></a>Promise used to return the result.</p>
</td>
</tr>
</tbody>
</table>
- Example:
- Return value
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
- Example
```
let promise = storage.put('startup', 'auto')
promise.then(() => {
let promiseput = storage.put('startup', 'auto')
promiseput.then(() => {
console.info("Put the value of startup successfully.")
}).catch((err) => {
console.info("Put the value of startup failed with err: " + err)
...
...
@@ -947,58 +452,27 @@ This method uses an asynchronous mode.
```
### hasSync<a name="section7273343143018"></a>
### hasSync
hasSync\(key: string\): boolean
hasSync(key: string): boolean
Checks whether the storage object contains data with the specified key.
Checks whether the storage object contains data with a given key.
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p8697139312"><a name="p8697139312"></a><a name="p8697139312"></a>Key of the data. It cannot be empty.</p>
<td class="cellrowborder" valign="top" width="48.12286689419795%" headers="mcps1.1.5.1.4 "><p id="p14699746114020"><a name="p14699746114020"></a><a name="p14699746114020"></a>Key of the data. It cannot be empty.</p>
<td class="cellrowborder" valign="top" width="48.12286689419795%" headers="mcps1.1.5.1.4 "><p id="p147004466406"><a name="p147004466406"></a><a name="p147004466406"></a>Callback used to return the result.</p>
<td class="cellrowborder" valign="top" width="59.76596782057533%" headers="mcps1.1.5.1.4 "><p id="p1433213456"><a name="p1433213456"></a><a name="p1433213456"></a>Key of the data. It cannot be empty.</p>
<td class="cellrowborder" valign="top" width="69.44%" headers="mcps1.1.3.1.2 "><p id="p202076136463"><a name="p202076136463"></a><a name="p202076136463"></a>Promise used to return the result.</p>
</td>
</tr>
</tbody>
</table>
- Example:
- Return value
| Type| Description|
| -------- | -------- |
| Promise<boolean> | Promise used to return the result.|
- Example
```
let promise = storage.has('startup')
promise.then((isExist) => {
let promisehas = storage.has('startup')
promisehas.then((isExist) => {
if (isExist) {
console.info("The key of startup is contained.")
}
...
...
@@ -1145,90 +549,44 @@ This method uses an asynchronous mode.
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p9338731476"><a name="p9338731476"></a><a name="p9338731476"></a>Key of the data. It cannot be empty.</p>
</td>
</tr>
</tbody>
</table>
- Example:
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the data. It cannot be empty.|
<td class="cellrowborder" valign="top" width="51.07752315943442%" headers="mcps1.1.5.1.4 "><p id="p76361658497"><a name="p76361658497"></a><a name="p76361658497"></a>Key of the data. It cannot be empty.</p>
<td class="cellrowborder" valign="top" width="51.07752315943442%" headers="mcps1.1.5.1.4 "><p id="p156361259495"><a name="p156361259495"></a><a name="p156361259495"></a>Callback used to return the result.</p>
</td>
</tr>
</tbody>
</table>
- Example:
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the data. It cannot be empty.|
| callback | AsyncCallback<void> | Yes| Callback used to return the execution result.|
- Example
```
storage.delete('startup', function (err) {
if (err) {
...
...
@@ -1240,61 +598,30 @@ This method uses an asynchronous mode.
```
### delete<a name="section11711858125016"></a>
### delete
delete\(key: string\): Promise<void\>
delete(key: string): Promise<void>
Deletes the data with the specified key from this storage object.
Deletes data with the specified key from this storage object.
This method uses an asynchronous mode.
This method uses an asynchronous callback to return the result.
<td class="cellrowborder" valign="top" width="82.99%" headers="mcps1.1.3.1.2 "><p id="p36981947155117"><a name="p36981947155117"></a><a name="p36981947155117"></a>Promise used to return the result.</p>
</td>
</tr>
</tbody>
</table>
- Example:
- Return value
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
- Example
```
let promise = storage.delete('startup')
promise.then(() => {
let promisedel = storage.delete('startup')
promisedel.then(() => {
console.info("Deleted startup key successfully.")
}).catch((err) => {
console.info("Delete startup key failed with err: " + err)
...
...
@@ -1302,56 +629,38 @@ This method uses an asynchronous mode.
```
### flushSync<a name="section1952191618523"></a>
### flushSync
flushSync\(\): void
flushSync(): void
Saves the modification of the current object to the current **Storage** instance and synchronizes the modification to the file.
Saves the modification of this object to the **Storage** instance and synchronizes the modification to the file.
<td class="cellrowborder" valign="top" width="53.13505607020965%" headers="mcps1.1.5.1.4 "><p id="p19851715105412"><a name="p19851715105412"></a><a name="p19851715105412"></a>Callback used to return the result.</p>
</td>
</tr>
</tbody>
</table>
- Example:
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<void> | Yes| Callback used to return the execution result.|
- Example
```
storage.flush(function (err) {
if (err) {
...
...
@@ -1363,36 +672,25 @@ This method uses an asynchronous mode.
```
### flush<a name="section524213130551"></a>
flush\(\): Promise<void\>
### flush
Saves the modification of the current object to the current **Storage** instance and stores the modification to the file in an asynchronous mode.
flush(): Promise<void>
This method uses an asynchronous mode.
Saves the modification of this object to the **Storage** instance and synchronizes the modification to the file.
- Return values
This method uses an asynchronous callback to return the result.
<td class="cellrowborder" valign="top" width="82.99%" headers="mcps1.1.3.1.2 "><p id="p1273364018550"><a name="p1273364018550"></a><a name="p1273364018550"></a>Promise used to return the result.</p>
<td class="cellrowborder" valign="top" width="51.32130667966845%" headers="mcps1.1.5.1.4 "><p id="p84590321224"><a name="p84590321224"></a><a name="p84590321224"></a>Callback used to return the result.</p>
</td>
</tr>
</tbody>
</table>
- Example:
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<void> | Yes| Callback used to return the execution result.|
- Example
```
storage.clear(function (err) {
if (err) {
...
...
@@ -1461,36 +741,25 @@ This method uses an asynchronous mode.
```
### clear<a name="section21300181536"></a>
clear\(\): Promise<void\>
### clear
Clears all data in a storage object.
clear(): Promise<void>
This method uses an asynchronous mode.
Clears this **Storage** object.
- Return values
This method uses an asynchronous callback to return the result.
<td class="cellrowborder" valign="top" width="79.62%" headers="mcps1.1.3.1.2 "><p id="p1337317471631"><a name="p1337317471631"></a><a name="p1337317471631"></a>Promise used to return the result.</p>
Subscribes to data changes. The **StorageObserver** needs to be implemented. When the value of the key subscribed to is changed, a callback will be invoked after **flush\(\)** or **flushSync\(\)** is executed.
Subscribes to data changes. The **StorageObserver** needs to be implemented. When the value of the key subscribed to is changed, a callback will be invoked after **flush()** or **flushSync()** is executed.