PrefetchCache


@Profile.ExperimentalUrlPrefetch
public final class PrefetchCache


PrefetchCache manages the configuration of the prefetch cache for a Profile.

It allows applications to tune the behavior of prefetch cache by setting limits such as the maximum number of prefetches and the time-to-live for prefetched responses. These configurations are applied to all WebViews associated with the profile.

Use getPrefetchCache to obtain the PrefetchCache instance for a specific profile.

Summary

Public methods

void
@RequiresFeature(name = WebViewFeature.PREFETCH_CACHE_V1, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@UiThread
@Profile.ExperimentalUrlPrefetch
setMaxPrefetches(@Nullable @IntRange(from = 1) Integer maxPrefetches)

Sets the maximum number of prefetches for the current browsing session.

void
@RequiresFeature(name = WebViewFeature.PREFETCH_CACHE_V1, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@UiThread
@Profile.ExperimentalUrlPrefetch
setPrefetchTtlSeconds(
    @Nullable @IntRange(from = 1) Integer prefetchTtlSeconds
)

Sets the maximum prefetch Time-to-Live (TTL) in seconds for the current browsing session.

Public methods

setMaxPrefetches

Added in 1.16.0-beta01
@RequiresFeature(name = WebViewFeature.PREFETCH_CACHE_V1, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@UiThread
@Profile.ExperimentalUrlPrefetch
public void setMaxPrefetches(@Nullable @IntRange(from = 1) Integer maxPrefetches)

Sets the maximum number of prefetches for the current browsing session.

These configurations will be applied to any prefetch requests made after they are set; they will not be applied to in-flight requests.

These configurations will be applied to WebViews that are associated with the Profile that owns this PrefetchCache.

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

Parameters
@Nullable @IntRange(from = 1) Integer maxPrefetches

the maximum number of prefetches to allow. Setting this value to null will use the default value.

Throws
java.lang.UnsupportedOperationException

if the PREFETCH_CACHE_V1 feature is not supported.

setPrefetchTtlSeconds

Added in 1.16.0-beta01
@RequiresFeature(name = WebViewFeature.PREFETCH_CACHE_V1, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@UiThread
@Profile.ExperimentalUrlPrefetch
public void setPrefetchTtlSeconds(
    @Nullable @IntRange(from = 1) Integer prefetchTtlSeconds
)

Sets the maximum prefetch Time-to-Live (TTL) in seconds for the current browsing session.

These configurations will be applied to any prefetch requests made after they are set; they will not be applied to in-flight requests.

These configurations will be applied to WebViews that are associated with the Profile that owns this PrefetchCache.

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

Parameters
@Nullable @IntRange(from = 1) Integer prefetchTtlSeconds

the TTL in seconds. Setting this value to null will use the default value.

Throws
java.lang.UnsupportedOperationException

if the PREFETCH_CACHE_V1 feature is not supported.