1e41f4b71Sopenharmony_ci# Setting Back-forward Cache
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciBy enabling the back-forward cache for **Web** components, you can navigate through the visited pages smoother and faster. 
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci## Enabling Back-forward Cache
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciYou can use [enableBackForwardCache()](../reference/apis-arkweb/js-apis-webview.md#enablebackforwardcache12) to enable the back-forward cache for the **Web** components.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ciThis API must be called before calling [initializeBrowserEngine()](../reference/apis-arkweb/js-apis-webview.md#initializewebengine) to initialize the kernel.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci```ts
12e41f4b71Sopenharmony_ci// EntryAbility.ets
13e41f4b71Sopenharmony_ciimport { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
14e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit';
15e41f4b71Sopenharmony_ciimport { window } from '@kit.ArkUI';
16e41f4b71Sopenharmony_ciimport { webview } from '@kit.ArkWeb';
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ciexport default class EntryAbility extends UIAbility {
19e41f4b71Sopenharmony_ci    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
20e41f4b71Sopenharmony_ci        let features = new webview.BackForwardCacheSupportedFeatures();
21e41f4b71Sopenharmony_ci        features.nativeEmbed = true;
22e41f4b71Sopenharmony_ci        features.mediaTakeOver = true;
23e41f4b71Sopenharmony_ci        webview.WebviewController.enableBackForwardCache(features);
24e41f4b71Sopenharmony_ci        webview.WebviewController.initializeWebEngine();
25e41f4b71Sopenharmony_ci        AppStorage.setOrCreate("abilityWant", want);
26e41f4b71Sopenharmony_ci    }
27e41f4b71Sopenharmony_ci}
28e41f4b71Sopenharmony_ci```
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci## Setting the Size and Live Time of Cached pages
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ciYou can use [setBackForwardCacheOptions()](../reference/apis-arkweb/js-apis-webview.md#setbackforwardcacheoptions12) to set the back-forward cache options for each **Web** component.
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ciIn the following example, the maximum number of pages that can be cached in the **Web** component is set to **10**, and each page is cached for 300s.
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci```ts
37e41f4b71Sopenharmony_ci// xxx.ts
38e41f4b71Sopenharmony_ciimport { webview } from '@kit.ArkWeb';
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci@Entry
41e41f4b71Sopenharmony_ci@Component
42e41f4b71Sopenharmony_cistruct Index {
43e41f4b71Sopenharmony_ci  controller: webview.WebviewController = new webview.WebviewController();
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci  build() {
46e41f4b71Sopenharmony_ci    Column() {
47e41f4b71Sopenharmony_ci      Row() {
48e41f4b71Sopenharmony_ci        Button("Add options").onClick((event: ClickEvent) => {
49e41f4b71Sopenharmony_ci          let options = new webview.BackForwardCacheOptions();
50e41f4b71Sopenharmony_ci          options.size = 10;
51e41f4b71Sopenharmony_ci          options.timeToLive = 300;
52e41f4b71Sopenharmony_ci          this.controller.setBackForwardCacheOptions(options);
53e41f4b71Sopenharmony_ci        })
54e41f4b71Sopenharmony_ci        Button("Backward").onClick((event: ClickEvent) => {
55e41f4b71Sopenharmony_ci          this.controller.backward();
56e41f4b71Sopenharmony_ci        })
57e41f4b71Sopenharmony_ci        Button("Forward").onClick((event: ClickEvent) => {
58e41f4b71Sopenharmony_ci          this.controller.forward();
59e41f4b71Sopenharmony_ci        })
60e41f4b71Sopenharmony_ci      }
61e41f4b71Sopenharmony_ci      Web({ src: "https://www.example.com", controller: this.controller })
62e41f4b71Sopenharmony_ci    }
63e41f4b71Sopenharmony_ci    .height('100%')
64e41f4b71Sopenharmony_ci    .width('100%')
65e41f4b71Sopenharmony_ci  }
66e41f4b71Sopenharmony_ci}
67e41f4b71Sopenharmony_ci```
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci<!--no_check-->