HttpCache


public final class HttpCache


HttpCache manages the configuration of the HTTP cache for a Profile.

Use getHttpCache to obtain the instance for a specific profile.

Summary

Public methods

@IntRange(from = 0) long

Returns the default HTTP cache quota in bytes.

@IntRange(from = 0) long

Returns the current cache quota in bytes.

boolean

Returns whether the cache quota is being automatically managed by WebView.

void
@UiThread
setQuotaBytes(@IntRange(from = 0) long quotaInBytes)

Sets the HTTP cache quota in bytes.

void

Use WebView's default automatic cache quota sizing.

Public methods

getDefaultQuotaBytes

@UiThread
public @IntRange(from = 0) long getDefaultQuotaBytes()

Returns the default HTTP cache quota in bytes. This is the cache quota (in bytes) that would be allocated to the associated profile if using WebView's automatic cache quota sizing.

The default quota may not be a stable size across sessions.

If you wish to use automatic quota management, call useDefaultQuota instead of supplying the output of this method to setQuotaBytes.

getQuotaBytes

@UiThread
public @IntRange(from = 0) long getQuotaBytes()

Returns the current cache quota in bytes.

This is the cache quota that is actually in effect for the associated profile, which may either be an automatic default value or a value previously set via setQuotaBytes (with possible adjustments).

isUsingDefaultQuota

@UiThread
public boolean isUsingDefaultQuota()

Returns whether the cache quota is being automatically managed by WebView.

See also
useDefaultQuota

setQuotaBytes

@UiThread
public void setQuotaBytes(@IntRange(from = 0) long quotaInBytes)

Sets the HTTP cache quota in bytes.

This overrides the automatic default.

A value greater than or equal to zero must be given. WebView may further enforce minimum/maximum constraints on the quota size, and values outside of this range will be automatically clamped. getQuotaBytes will reflect such quota adjustments.

Passing a value of zero will neither disable nor fully clear the cache, but will only reduce its quota to the smallest possible value.

A cache quota will take immediate effect, persist across restarts, and will not automatically expire.

If a call to this method decreases the cache quota, it may trigger background cache evictions, which could have performance impacts. This method does not wait for evictions to complete.

You should only use this API on a Profile that your code owns. Setting or unsetting a quota on a Profile (particularly the Default Profile) that is shared by multiple libraries or activities may result in degradation of performance or overuse of disk space.

If you wish to use automatic quota management, call useDefaultQuota instead of supplying the output of getDefaultQuotaBytes method to this method.

useDefaultQuota

@UiThread
public void useDefaultQuota()

Use WebView's default automatic cache quota sizing.

The default quota may not be a stable size across sessions.

This will take immediate effect and forget any previously configured manual quota.

If a call to this method decreases the cache quota, it may trigger background cache evictions, which could have performance impacts. This method does not wait for evictions to complete.

You should only use this API on a Profile that your code owns. Setting or unsetting a quota on a Profile (particularly the Default Profile) that is shared by multiple libraries or activities may result in degradation of performance or overuse of disk space.