# BackForwardCacheSettings

Artifact: [androidx.webkit:webkit](https://developer.android.com/jetpack/androidx/releases/webkit) [View Source](https://cs.android.com/search?q=file:androidx/webkit/BackForwardCacheSettings.java+class:androidx.webkit.BackForwardCacheSettings) Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

*** ** * ** ***


```
@WebSettingsCompat.ExperimentalBackForwardCacheSettings
public class BackForwardCacheSettings
```

<br />

*** ** * ** ***

A class for developers to configure the back-forward cache on a `https://developer.android.com/reference/android/webkit/WebView.html`.

The back-forward cache is a browser feature that improves the user experience by keeping pages alive for a limited time after the user navigates away from them. If the user navigates back or forward, the page is reused for a fast back navigation.

Example:

```
BackForwardCacheSettings settings =
        WebSettingsCompat.getBackForwardCacheSettings(webView.getSettings());
settings.setTimeoutSeconds(600);
settings.setMaxPagesInCache(10);
```

## Summary

| ### Public methods |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int` | `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(name = https://developer.android.com/reference/androidx/webkit/WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") https://developer.android.com/reference/androidx/webkit/BackForwardCacheSettings#getMaxPagesInCache()()` Returns the maximum number of pages that can be stored in the back-forward cache. |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long` | `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(name = https://developer.android.com/reference/androidx/webkit/WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") https://developer.android.com/reference/androidx/webkit/BackForwardCacheSettings#getTimeoutSeconds()()` Returns the timeout for pages in the back-forward cache, in seconds. |
| `boolean` | `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(name = https://developer.android.com/reference/androidx/webkit/WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V4, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") @https://developer.android.com/reference/androidx/webkit/WebSettingsCompat.ExperimentalBackForwardCacheSettings https://developer.android.com/reference/androidx/webkit/BackForwardCacheSettings#isKeepForwardEntriesEnabled()()` Returns whether to keep forward cache entries when the back-forward cache is enabled. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(name = https://developer.android.com/reference/androidx/webkit/WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V4, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") @https://developer.android.com/reference/androidx/webkit/WebSettingsCompat.ExperimentalBackForwardCacheSettings https://developer.android.com/reference/androidx/webkit/BackForwardCacheSettings#setKeepForwardEntriesEnabled(boolean)(boolean keepForwardEntries)` Sets whether to keep forward cache entries when the back-forward cache is enabled. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(name = https://developer.android.com/reference/androidx/webkit/WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") https://developer.android.com/reference/androidx/webkit/BackForwardCacheSettings#setMaxPagesInCache(int)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int maxPagesInCache)` Sets the maximum number of pages that can be stored in the back-forward cache. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(name = https://developer.android.com/reference/androidx/webkit/WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") https://developer.android.com/reference/androidx/webkit/BackForwardCacheSettings#setTimeoutSeconds(long)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long timeoutSeconds)` Sets the timeout for pages in the back-forward cache. |

## Public methods

### getMaxPagesInCache

Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

```
@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public @IntRange(from = 0) int getMaxPagesInCache()
```

Returns the maximum number of pages that can be stored in the back-forward cache.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` | if the `https://developer.android.com/reference/androidx/webkit/WebViewFeature#BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3()` feature is not supported. This should be checked before use with `https://developer.android.com/reference/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String)`. |

### getTimeoutSeconds

Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

```
@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public @IntRange(from = 0) long getTimeoutSeconds()
```

Returns the timeout for pages in the back-forward cache, in seconds.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` | if the `https://developer.android.com/reference/androidx/webkit/WebViewFeature#BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3()` feature is not supported. This should be checked before use with `https://developer.android.com/reference/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String)`. |

### isKeepForwardEntriesEnabled

Added in [1.16.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.16.0)

```
@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V4, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@WebSettingsCompat.ExperimentalBackForwardCacheSettings
public boolean isKeepForwardEntriesEnabled()
```

Returns whether to keep forward cache entries when the back-forward cache is enabled.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` | if the `https://developer.android.com/reference/androidx/webkit/WebViewFeature#BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V4()` feature is not supported. This should be checked before use with `https://developer.android.com/reference/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String)`. |

### setKeepForwardEntriesEnabled

Added in [1.16.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.16.0)

```
@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V4, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@WebSettingsCompat.ExperimentalBackForwardCacheSettings
public void setKeepForwardEntriesEnabled(boolean keepForwardEntries)
```

Sets whether to keep forward cache entries when the back-forward cache is enabled.

| Parameters |
|---|---|
| `boolean keepForwardEntries` | Whether to keep forward cache entries. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` | if the `https://developer.android.com/reference/androidx/webkit/WebViewFeature#BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V4()` feature is not supported. This should be checked before use with `https://developer.android.com/reference/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String)`. |

### setMaxPagesInCache

Added in [1.16.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.16.0)

```
@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public void setMaxPagesInCache(@IntRange(from = 0) int maxPagesInCache)
```

Sets the maximum number of pages that can be stored in the back-forward cache.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int maxPagesInCache` | The maximum number of pages. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` | if the `https://developer.android.com/reference/androidx/webkit/WebViewFeature#BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3()` feature is not supported. This should be checked before use with `https://developer.android.com/reference/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String)`. |

### setTimeoutSeconds

Added in [1.16.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.16.0)

```
@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public void setTimeoutSeconds(@IntRange(from = 0) long timeoutSeconds)
```

Sets the timeout for pages in the back-forward cache.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long timeoutSeconds` | The timeout in seconds. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` | if the `https://developer.android.com/reference/androidx/webkit/WebViewFeature#BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3()` feature is not supported. This should be checked before use with `https://developer.android.com/reference/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String)`. |