提交 84e2bfe7 编写于 作者: G ge-yafang

update docs

Signed-off-by: Nge-yafang <geyafang@huawei.com>
上级 aed19735
...@@ -732,11 +732,11 @@ class EntryAbility extends UIAbility { ...@@ -732,11 +732,11 @@ class EntryAbility extends UIAbility {
} }
``` ```
## data_preferences.removePreferencesFromCache<sup>10+</sup> ## data_preferences.removePreferencesFromCacheSync<sup>10+</sup>
removePreferencesFromCache(context: Context, options: Options, callback: AsyncCallback&lt;void&gt;): void removePreferencesFromCacheSync(context: Context, name: string): void
从缓存中移出指定的Preferences实例,使用callback异步回调 从缓存中移出指定的Preferences实例,此为同步接口
应用首次调用[getPreferences](#data_preferencesgetpreferences)接口获取某个Preferences实例后,该实例会被会被缓存起来,后续再次[getPreferences](#data_preferencesgetpreferences)时不会再次从持久化文件中读取,直接从缓存中获取Preferences实例。调用此接口移出缓存中的实例之后,再次getPreferences将会重新读取持久化文件,生成新的Preferences实例。 应用首次调用[getPreferences](#data_preferencesgetpreferences)接口获取某个Preferences实例后,该实例会被会被缓存起来,后续再次[getPreferences](#data_preferencesgetpreferences)时不会再次从持久化文件中读取,直接从缓存中获取Preferences实例。调用此接口移出缓存中的实例之后,再次getPreferences将会重新读取持久化文件,生成新的Preferences实例。
...@@ -747,19 +747,9 @@ removePreferencesFromCache(context: Context, options: Options, callback: AsyncCa ...@@ -747,19 +747,9 @@ removePreferencesFromCache(context: Context, options: Options, callback: AsyncCa
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ------- | ------------------------------------- | ---- | ----------------------- |
| context | Context | 是 | 应用上下文。<br>FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)<br>Stage模型的应用Context定义见[Context](js-apis-inner-application-uiAbilityContext.md)。 | | context | Context | 是 | 应用上下文。<br>FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)<br>Stage模型的应用Context定义见[Context](js-apis-inner-application-uiAbilityContext.md)。 |
| options | [Options](#options10) | 是 | 与Preferences实例相关的配置选项。 | | name | string | 是 | Preferences实例的名称。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当移除成功,err为undefined,否则为错误对象。 |
**错误码:**
以下错误码的详细介绍请参见[用户首选项错误码](../errorcodes/errorcode-preferences.md)
| 错误码ID | 错误信息 |
| -------- | ------------------------------ |
| 15501001 | Only supported in stage mode. |
| 15501002 | The data group id is not valid. |
**示例:** **示例:**
...@@ -770,14 +760,8 @@ FA模型示例: ...@@ -770,14 +760,8 @@ FA模型示例:
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context = featureAbility.getContext();
try { try {
data_preferences.removePreferencesFromCache(context, { name: 'mystore' }, function (err) { data_preferences.removePreferencesFromCacheSync(context, 'mystore');
if (err) { } catch(err) {
console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
return;
}
console.info("Succeeded in removing preferences.");
})
} catch (err) {
console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -790,14 +774,8 @@ import UIAbility from '@ohos.app.ability.UIAbility'; ...@@ -790,14 +774,8 @@ import UIAbility from '@ohos.app.ability.UIAbility';
class EntryAbility extends UIAbility { class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
try { try {
data_preferences.removePreferencesFromCache(this.context, { name: 'mystore', dataGroupId:'myId' }, function (err) { data_preferences.removePreferencesFromCacheSync(this.context, 'mystore');
if (err) { } catch(err) {
console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
return;
}
console.info("Succeeded in removing preferences.");
})
} catch (err) {
console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
} }
} }
...@@ -806,9 +784,9 @@ class EntryAbility extends UIAbility { ...@@ -806,9 +784,9 @@ class EntryAbility extends UIAbility {
## data_preferences.removePreferencesFromCache<sup>10+</sup> ## data_preferences.removePreferencesFromCache<sup>10+</sup>
removePreferencesFromCache(context: Context, options: Options): Promise&lt;void&gt; removePreferencesFromCache(context: Context, options: Options, callback: AsyncCallback&lt;void&gt;): void
从缓存中移出指定的Preferences实例,使用Promise异步回调。 从缓存中移出指定的Preferences实例,使用callback异步回调。
应用首次调用[getPreferences](#data_preferencesgetpreferences)接口获取某个Preferences实例后,该实例会被会被缓存起来,后续再次[getPreferences](#data_preferencesgetpreferences)时不会再次从持久化文件中读取,直接从缓存中获取Preferences实例。调用此接口移出缓存中的实例之后,再次getPreferences将会重新读取持久化文件,生成新的Preferences实例。 应用首次调用[getPreferences](#data_preferencesgetpreferences)接口获取某个Preferences实例后,该实例会被会被缓存起来,后续再次[getPreferences](#data_preferencesgetpreferences)时不会再次从持久化文件中读取,直接从缓存中获取Preferences实例。调用此接口移出缓存中的实例之后,再次getPreferences将会重新读取持久化文件,生成新的Preferences实例。
...@@ -819,15 +797,10 @@ removePreferencesFromCache(context: Context, options: Options): Promise&lt;void& ...@@ -819,15 +797,10 @@ removePreferencesFromCache(context: Context, options: Options): Promise&lt;void&
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------- | ---------------- | ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | -------- | ------------------------- | ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| context | Context | 是 | 应用上下文。<br>FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)<br>Stage模型的应用Context定义见[Context](js-apis-inner-application-uiAbilityContext.md)。 | | context | Context | 是 | 应用上下文。<br>FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)<br>Stage模型的应用Context定义见[Context](js-apis-inner-application-uiAbilityContext.md)。 |
| options | [Options](#options10) | 是 | 与Preferences实例相关的配置选项。 | | options | [Options](#options10) | 是 | 与Preferences实例相关的配置选项。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当移除成功,err为undefined,否则为错误对象。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**错误码:** **错误码:**
...@@ -847,13 +820,14 @@ FA模型示例: ...@@ -847,13 +820,14 @@ FA模型示例:
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context = featureAbility.getContext();
try { try {
let promise = data_preferences.removePreferencesFromCache(context, { name: 'mystore' }); data_preferences.removePreferencesFromCache(context, { name: 'mystore' }, function (err) {
promise.then(() => { if (err) {
console.info("Succeeded in removing preferences.");
}).catch((err) => {
console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
return;
}
console.info("Succeeded in removing preferences.");
}) })
} catch(err) { } catch (err) {
console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -866,24 +840,25 @@ import UIAbility from '@ohos.app.ability.UIAbility'; ...@@ -866,24 +840,25 @@ import UIAbility from '@ohos.app.ability.UIAbility';
class EntryAbility extends UIAbility { class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
try { try {
let promise = data_preferences.removePreferencesFromCache(this.context, { name: 'mystore', dataGroupId:'myId' }); data_preferences.removePreferencesFromCache(this.context, { name: 'mystore', dataGroupId:'myId' }, function (err) {
promise.then(() => { if (err) {
console.info("Succeeded in removing preferences.");
}).catch((err) => {
console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
return;
}
console.info("Succeeded in removing preferences.");
}) })
} catch(err) { } catch (err) {
console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
} }
} }
} }
``` ```
## data_preferences.removePreferencesFromCacheSync<sup>10+</sup> ## data_preferences.removePreferencesFromCache<sup>10+</sup>
removePreferencesFromCacheSync(context: Context, options: Options):void removePreferencesFromCache(context: Context, options: Options): Promise&lt;void&gt;
从缓存中移出指定的Preferences实例,此为同步接口 从缓存中移出指定的Preferences实例,使用Promise异步回调
应用首次调用[getPreferences](#data_preferencesgetpreferences)接口获取某个Preferences实例后,该实例会被会被缓存起来,后续再次[getPreferences](#data_preferencesgetpreferences)时不会再次从持久化文件中读取,直接从缓存中获取Preferences实例。调用此接口移出缓存中的实例之后,再次getPreferences将会重新读取持久化文件,生成新的Preferences实例。 应用首次调用[getPreferences](#data_preferencesgetpreferences)接口获取某个Preferences实例后,该实例会被会被缓存起来,后续再次[getPreferences](#data_preferencesgetpreferences)时不会再次从持久化文件中读取,直接从缓存中获取Preferences实例。调用此接口移出缓存中的实例之后,再次getPreferences将会重新读取持久化文件,生成新的Preferences实例。
...@@ -894,16 +869,22 @@ removePreferencesFromCacheSync(context: Context, options: Options):void ...@@ -894,16 +869,22 @@ removePreferencesFromCacheSync(context: Context, options: Options):void
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------- | --------------------- | ---- | ------------------------------------------------------------ | | ------- | ---------------- | ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| context | Context | 是 | 应用上下文。<br>FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)<br>Stage模型的应用Context定义见[Context](js-apis-inner-application-uiAbilityContext.md)。 | | context | Context | 是 | 应用上下文。<br>FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)<br>Stage模型的应用Context定义见[Context](js-apis-inner-application-uiAbilityContext.md)。 |
| options | [Options](#options10) | 是 | 与Preferences实例相关的配置选项。 | | options | [Options](#options10) | 是 | 与Preferences实例相关的配置选项。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[用户首选项错误码](../errorcodes/errorcode-preferences.md) 以下错误码的详细介绍请参见[用户首选项错误码](../errorcodes/errorcode-preferences.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| -------- | ------------------------------- | | -------- | ------------------------------ |
| 15501001 | Only supported in stage mode. | | 15501001 | Only supported in stage mode. |
| 15501002 | The data group id is not valid. | | 15501002 | The data group id is not valid. |
...@@ -916,7 +897,12 @@ FA模型示例: ...@@ -916,7 +897,12 @@ FA模型示例:
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context = featureAbility.getContext();
try { try {
data_preferences.removePreferencesFromCacheSync(context, { name: 'mystore' }); let promise = data_preferences.removePreferencesFromCache(context, { name: 'mystore' });
promise.then(() => {
console.info("Succeeded in removing preferences.");
}).catch((err) => {
console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
})
} catch(err) { } catch(err) {
console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
} }
...@@ -930,7 +916,12 @@ import UIAbility from '@ohos.app.ability.UIAbility'; ...@@ -930,7 +916,12 @@ import UIAbility from '@ohos.app.ability.UIAbility';
class EntryAbility extends UIAbility { class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
try { try {
data_preferences.removePreferencesFromCacheSync(this.context, { name: 'mystore', dataGroupId:'myId' }); let promise = data_preferences.removePreferencesFromCache(this.context, { name: 'mystore', dataGroupId:'myId' });
promise.then(() => {
console.info("Succeeded in removing preferences.");
}).catch((err) => {
console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
})
} catch(err) { } catch(err) {
console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册