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

@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.

Unit

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

Unit
@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V3, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
setMaxPagesInCache(maxPagesInCache: @IntRange(from = 0) 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: @IntRange(from = 0) 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(): @IntRange(from = 0) 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(): @IntRange(from = 0) 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.

isKeepForwardEntriesEnabled

Added in 1.16.0-beta01
@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE_SETTINGS_EXPERIMENTAL_V4, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@WebSettingsCompat.ExperimentalBackForwardCacheSettings
fun isKeepForwardEntriesEnabled(): Boolean

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
fun setKeepForwardEntriesEnabled(keepForwardEntries: Boolean): Unit

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
keepForwardEntries: Boolean

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")
fun setMaxPagesInCache(maxPagesInCache: @IntRange(from = 0) 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: @IntRange(from = 0) Int

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")
fun setTimeoutSeconds(timeoutSeconds: @IntRange(from = 0) 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: @IntRange(from = 0) Long

The timeout in seconds.