# HttpCache

Artifact: [androidx.webkit:webkit](https://developer.android.com/jetpack/androidx/releases/webkit) [View Source](https://cs.android.com/search?q=file:androidx/webkit/HttpCache.java+class:androidx.webkit.HttpCache) Added in [1.17.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.17.0)

*** ** * ** ***


```
class HttpCache
```

<br />

*** ** * ** ***

HttpCache manages the configuration of the HTTP cache for a `https://developer.android.com/reference/kotlin/androidx/webkit/Profile`.

Use `https://developer.android.com/reference/kotlin/androidx/webkit/Profile#getHttpCache()` to obtain the instance for a specific profile.

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/webkit/HttpCache#equals(java.lang.Object)(obj: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` Compares this HttpCache with the specified object for equality. |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/UiThread https://developer.android.com/reference/kotlin/androidx/webkit/HttpCache#getDefaultQuotaBytes()()` Returns the default HTTP cache quota in bytes. |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/UiThread https://developer.android.com/reference/kotlin/androidx/webkit/HttpCache#getQuotaBytes()()` Returns the current cache quota in bytes. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/webkit/HttpCache#hashCode()()` Returns a hash code value for the object, consistent with `https://developer.android.com/reference/kotlin/androidx/webkit/HttpCache#equals(java.lang.Object)`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/UiThread https://developer.android.com/reference/kotlin/androidx/webkit/HttpCache#isUsingDefaultQuota()()` Returns whether the cache quota is being automatically managed by WebView. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/UiThread https://developer.android.com/reference/kotlin/androidx/webkit/HttpCache#setQuotaBytes(long)(quotaInBytes: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Sets the HTTP cache quota in bytes. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/UiThread https://developer.android.com/reference/kotlin/androidx/webkit/HttpCache#useDefaultQuota()()` Use WebView's default automatic cache quota sizing. |

## Public functions

### equals

```
fun equals(obj: Any?): Boolean
```

Compares this HttpCache with the specified object for equality.

Two `https://developer.android.com/reference/kotlin/androidx/webkit/HttpCache` instances are considered equal if they are associated with the same `https://developer.android.com/reference/kotlin/androidx/webkit/Profile` (i.e., they have the same profile name).

| Parameters |
|---|---|
| `obj: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | the object to compare with. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the objects are equal; `false` otherwise. |

### getDefaultQuotaBytes

Added in [1.17.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.17.0)

```
@UiThread
fun getDefaultQuotaBytes(): @IntRange(from = 0) Long
```

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 `https://developer.android.com/reference/kotlin/androidx/webkit/HttpCache#useDefaultQuota()` instead of supplying the output of this method to `https://developer.android.com/reference/kotlin/androidx/webkit/HttpCache#setQuotaBytes(long)`.

### getQuotaBytes

Added in [1.17.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.17.0)

```
@UiThread
fun getQuotaBytes(): @IntRange(from = 0) Long
```

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 `https://developer.android.com/reference/kotlin/androidx/webkit/HttpCache#setQuotaBytes(long)` (with possible adjustments).

### hashCode

```
fun hashCode(): Int
```

Returns a hash code value for the object, consistent with `https://developer.android.com/reference/kotlin/androidx/webkit/HttpCache#equals(java.lang.Object)`.

### isUsingDefaultQuota

Added in [1.17.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.17.0)

```
@UiThread
fun isUsingDefaultQuota(): Boolean
```

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

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/webkit/HttpCache#useDefaultQuota()` |   |

### setQuotaBytes

Added in [1.17.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.17.0)

```
@UiThread
fun setQuotaBytes(quotaInBytes: @IntRange(from = 0) Long): Unit
```

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. `https://developer.android.com/reference/kotlin/androidx/webkit/HttpCache#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 `https://developer.android.com/reference/kotlin/androidx/webkit/HttpCache#useDefaultQuota()` instead of supplying the output of `https://developer.android.com/reference/kotlin/androidx/webkit/HttpCache#getDefaultQuotaBytes()` method to this method.

### useDefaultQuota

Added in [1.17.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.17.0)

```
@UiThread
fun useDefaultQuota(): Unit
```

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.