BackForwardCacheSettings


@WebSettingsCompat.ExperimentalBackForwardCacheSettings
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 functions

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.

Unit
@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
setMaxPagesInCache(maxPagesInCache: Int)

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

Unit
@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
setTimeoutSeconds(timeoutSeconds: Long)

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

Public functions

getMaxPagesInCache

Added in 1.15.0
@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
fun getMaxPagesInCache(): Int

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")
fun getTimeoutSeconds(): Long

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")
fun setMaxPagesInCache(maxPagesInCache: Int): Unit

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
maxPagesInCache: Int

The maximum number of pages.

setTimeoutSeconds

@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
fun setTimeoutSeconds(timeoutSeconds: Long): Unit

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
timeoutSeconds: Long

The timeout in seconds.