BackForwardCacheSettings


@WebSettingsCompat.ExperimentalBackForwardCacheSettings
public class BackForwardCacheSettings


A class for developers to configure the back-forward cache on a WebView.

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

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

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

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

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

boolean

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

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

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

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

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

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

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

Public methods

getMaxPagesInCache

Added in 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.

This method should only be called if isFeatureSupported returns true for BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3.

getTimeoutSeconds

Added in 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.

This method should only be called if isFeatureSupported returns true for BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3.

isKeepForwardEntriesEnabled

Added in 1.16.0-beta01
@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.

This method should only be called if isFeatureSupported returns true for BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V4.

setKeepForwardEntriesEnabled

Added in 1.16.0-beta01
@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.

This method should only be called if isFeatureSupported returns true for BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V4.

Parameters
boolean keepForwardEntries

Whether to keep forward cache entries.

setMaxPagesInCache

Added in 1.16.0-beta01
@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.

This method should only be called if isFeatureSupported returns true for BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3.

Parameters
@IntRange(from = 0) int maxPagesInCache

The maximum number of pages.

setTimeoutSeconds

Added in 1.16.0-beta01
@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.

This method should only be called if isFeatureSupported returns true for BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3.

Parameters
@IntRange(from = 0) long timeoutSeconds

The timeout in seconds.