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

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.

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.

void
@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
setMaxPagesInCache(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(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 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 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.

setMaxPagesInCache

@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public void setMaxPagesInCache(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
int maxPagesInCache

The maximum number of pages.

setTimeoutSeconds

@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public void setTimeoutSeconds(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
long timeoutSeconds

The timeout in seconds.