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

boolean

Compares this HttpCache with the specified object for equality.

@IntRange(from = 0) long

Returns the default HTTP cache quota in bytes.

@IntRange(from = 0) long

Returns the current cache quota in bytes.

int

Returns a hash code value for the object, consistent with equals.

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

equals

public boolean equals(@Nullable Object obj)

Compares this HttpCache with the specified object for equality.

Two HttpCache instances are considered equal if they are associated with the same Profile (i.e., they have the same profile name).

Parameters
@Nullable Object obj

the object to compare with.

Returns
boolean

true if the objects are equal; false otherwise.

getDefaultQuotaBytes

Added in 1.17.0
@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

Added in 1.17.0
@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).

hashCode

public int hashCode()

Returns a hash code value for the object, consistent with equals.

isUsingDefaultQuota

Added in 1.17.0
@UiThread
public boolean isUsingDefaultQuota()

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

See also
useDefaultQuota

setQuotaBytes

Added in 1.17.0
@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

Added in 1.17.0
@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.