未验证 提交 f9e857d1 编写于 作者: O openharmony_ci 提交者: Gitee

!19988 [翻译完成】#I79J8H

Merge pull request !19988 from Annie_wang/PR18938
......@@ -10,7 +10,7 @@ The **Preferences** module provides APIs for processing data in the form of key-
User applications call **Preference** through the JS interface to read and write data files. You can load the data of a **Preferences** persistence file to a **Preferences** instance. Each file uniquely corresponds to an instance. The system stores the instance in memory through a static container until the instance is removed from the memory or the file is deleted. The following figure illustrates how **Preference** works.
The preference persistent file of an application is stored in the application sandbox. You can use **context** to obtain the file path. For details, see [Obtaining the Application Development Path](../application-models/application-context-stage.md#obtaining-the-application-development-path).
The preference persistent file of an application is stored in the application sandbox. You can use **context** to obtain the file path. For details, see [Obtaining Application File Paths](../application-models/application-context-stage.md#obtaining-application-file-paths).
**Figure 1** Preferences working mechanism
......@@ -21,7 +21,7 @@ The preference persistent file of an application is stored in the application sa
- The key in a KV pair must be a string and cannot be empty or exceed 80 bytes.
- If the value is of the string type, it can be empty or a string not longer than 8192 bytes.
- If the value is of the string type, use the UTF-8 encoding format. It can be empty or a string not longer than 8192 bytes.
- The memory usage increases with the amount of **Preferences** data. The maximum number of data records recommended is 10,000. Otherwise, high memory overheads will be caused.
......@@ -30,7 +30,7 @@ The preference persistent file of an application is stored in the application sa
The following table lists the APIs used for preferences data persistence. Most of the APIs are executed asynchronously, using a callback or promise to return the result. The following table uses the callback-based APIs as an example. For more information about the APIs, see [User Preferences](../reference/apis/js-apis-data-preferences.md).
| API| Description|
| API| Description|
| -------- | -------- |
| getPreferences(context: Context, name: string, callback: AsyncCallback<Preferences>): void | Obtain a **Preferences** instance.|
| put(key: string, value: ValueType, callback: AsyncCallback<void>): void | Writes data to the Preferences instance. You can use **flush()** to persist the **Preferences** instance data.|
......@@ -248,3 +248,4 @@ The following table lists the APIs used for preferences data persistence. Most o
console.error(`Failed to delete preferences. Code:${err.code}, message:${err.message}`);
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册