# SieveCache

Artifact: [androidx.collection:collection](https://developer.android.com/jetpack/androidx/releases/collection) [View Source](https://cs.android.com/search?q=file:androidx/collection/SieveCache.kt+class:androidx.collection.SieveCache) Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/collection#1.5.0)

*** ** * ** ***

<br />

```
public final class SieveCache<K extends Object, V extends Object>
```

<br />

*** ** * ** ***

`https://developer.android.com/reference/androidx/collection/SieveCache` is an in-memory cache that holds strong references to a limited number of values determined by the cache's `https://developer.android.com/reference/androidx/collection/SieveCache#(kotlin.Int,kotlin.Int,kotlin.Function2,kotlin.Function1,kotlin.Function4)` and the size of each value. When a value is added to a full cache, one or more existing values are evicted from the cache using the [SIEVE algorithm](https://cachemon.github.io/SIEVE-website/). Complete details about the algorithm can be found in Zhang et al., 2024, SIEVE is Simpler than LRU: an Efficient Turn-Key Eviction Algorithm for Web Caches, NSDI'24 ([paper](https://www.usenix.org/system/files/nsdi24-zhang-yazhuo.pdf)).

Contrary to `https://developer.android.com/reference/androidx/collection/LruCache`, `https://developer.android.com/reference/androidx/collection/SieveCache` does not maintain a list of entries based on their access order, but on their insertion order. Eviction candidates are found by keeping track of the "visited" status of each entry. This means that reading a value using `https://developer.android.com/reference/androidx/collection/SieveCache#get(kotlin.Any)` prevents that entry from becoming an eviction candidate. In practice, `https://developer.android.com/reference/androidx/collection/SieveCache` offers better hit ratio compared to `https://developer.android.com/reference/androidx/collection/LruCache`.

The underlying implementation is also designed to avoid all allocations on insertion, removal, retrieval, and iteration. Allocations may still happen on insertion when the underlying storage needs to grow to accommodate newly added entries to the table. In addition, this implementation minimizes memory usage by avoiding the use of separate objects to hold key/value pairs. The implementation follows the implementation of `https://developer.android.com/reference/androidx/collection/ScatterMap`.

By default, the size of the cache is measured in number of entries. The caller can choose the size and size unit of the values by passing their own `https://developer.android.com/reference/androidx/collection/SieveCache#(kotlin.Int,kotlin.Int,kotlin.Function2,kotlin.Function1,kotlin.Function4)` lambda, invoked whenever the cache needs to query the size of a value.

The `https://developer.android.com/reference/androidx/collection/SieveCache#(kotlin.Int,kotlin.Int,kotlin.Function2,kotlin.Function1,kotlin.Function4)` lambda can be used to compute values on demand from a key when querying for an entry that does not exist in the cache.

When a cached value is removed, either directly by the caller or via the eviction mechanism, you can use the `https://developer.android.com/reference/androidx/collection/SieveCache#(kotlin.Int,kotlin.Int,kotlin.Function2,kotlin.Function1,kotlin.Function4)` lambda to execute any side effect or perform any necessary cleanup.

This implementation is not thread-safe: if multiple threads access this container concurrently, and one or more threads modify the structure of the map (insertion or removal for instance), the calling code must provide the appropriate synchronization. Multiple threads are safe to read from this map concurrently if no write is happening.

A `https://developer.android.com/reference/androidx/collection/SieveCache` can hold a maximum of `Int.MAX_VALUE - 1` entries, independent of their computed size.

## Summary

| ### Public constructors |
|---|
| `<K extends https://developer.android.com/reference/java/lang/Object.html, V extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/collection/SieveCache#SieveCache(kotlin.Int,kotlin.Int,kotlin.Function2,kotlin.Function1,kotlin.Function4)( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 1, to = 2147483646) int maxSize, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0, to = 2147483646) int initialCapacity, @https://developer.android.com/reference/androidx/annotation/NonNull Function2<@https://developer.android.com/reference/androidx/annotation/NonNull key, @https://developer.android.com/reference/androidx/annotation/NonNull value, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Integer.html> sizeOf, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull key, V> createValueFromKey, @https://developer.android.com/reference/androidx/annotation/NonNull Function4<@https://developer.android.com/reference/androidx/annotation/NonNull key, @https://developer.android.com/reference/androidx/annotation/NonNull oldValue, newValue, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> onEntryRemoved )` Creates a new `https://developer.android.com/reference/androidx/collection/SieveCache`. |

| ### Public methods |
|---|---|
| `final boolean` | `https://developer.android.com/reference/androidx/collection/SieveCache#all(kotlin.Function2)(@https://developer.android.com/reference/androidx/annotation/NonNull Function2<@https://developer.android.com/reference/androidx/annotation/NonNull K, @https://developer.android.com/reference/androidx/annotation/NonNull V, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html> predicate)` Returns true if all entries match the given `https://developer.android.com/reference/androidx/collection/SieveCache#all(kotlin.Function2)`. |
| `final boolean` | `https://developer.android.com/reference/androidx/collection/SieveCache#any()()` Returns `true` if this cache has at least one entry. |
| `final boolean` | `https://developer.android.com/reference/androidx/collection/SieveCache#any(kotlin.Function2)(@https://developer.android.com/reference/androidx/annotation/NonNull Function2<@https://developer.android.com/reference/androidx/annotation/NonNull K, @https://developer.android.com/reference/androidx/annotation/NonNull V, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html> predicate)` Returns true if at least one entry matches the given `https://developer.android.com/reference/androidx/collection/SieveCache#any(kotlin.Function2)`. |
| `final boolean` | `https://developer.android.com/reference/androidx/collection/SieveCache#contains(kotlin.Any)(@https://developer.android.com/reference/androidx/annotation/NonNull K key)` Returns true if the specified `https://developer.android.com/reference/androidx/collection/SieveCache#contains(kotlin.Any)` is present in this cache, false otherwise. |
| `final boolean` | `https://developer.android.com/reference/androidx/collection/SieveCache#containsKey(kotlin.Any)(@https://developer.android.com/reference/androidx/annotation/NonNull K key)` Returns true if the specified `https://developer.android.com/reference/androidx/collection/SieveCache#containsKey(kotlin.Any)` is present in this cache, false otherwise. |
| `final boolean` | `https://developer.android.com/reference/androidx/collection/SieveCache#containsValue(kotlin.Any)(@https://developer.android.com/reference/androidx/annotation/NonNull V value)` Returns true if the specified `https://developer.android.com/reference/androidx/collection/SieveCache#containsValue(kotlin.Any)` is present in this hash map, false otherwise. |
| `final int` | `https://developer.android.com/reference/androidx/collection/SieveCache#count()()` Returns the number of entries in this cache. |
| `final int` | `https://developer.android.com/reference/androidx/collection/SieveCache#count(kotlin.Function2)(@https://developer.android.com/reference/androidx/annotation/NonNull Function2<@https://developer.android.com/reference/androidx/annotation/NonNull K, @https://developer.android.com/reference/androidx/annotation/NonNull V, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html> predicate)` Returns the number of entries matching the given `https://developer.android.com/reference/androidx/collection/SieveCache#count(kotlin.Function2)`. |
| `boolean` | `https://developer.android.com/reference/androidx/collection/SieveCache#equals(kotlin.Any)(https://developer.android.com/reference/java/lang/Object.html other)` Compares the specified object `https://developer.android.com/reference/androidx/collection/SieveCache#equals(kotlin.Any)` with this cache for equality. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#evictAll()()` Removes all the entries from this cache. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#forEach(kotlin.Function2)(@https://developer.android.com/reference/androidx/annotation/NonNull Function2<@https://developer.android.com/reference/androidx/annotation/NonNull key, @https://developer.android.com/reference/androidx/annotation/NonNull value, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> block)` Iterates over every key/value pair stored in this cache by invoking the specified `https://developer.android.com/reference/androidx/collection/SieveCache#forEach(kotlin.Function2)` lambda. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#forEachKey(kotlin.Function1)(@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull key, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> block)` Iterates over every key stored in this cache by invoking the specified `https://developer.android.com/reference/androidx/collection/SieveCache#forEachKey(kotlin.Function1)` lambda. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#forEachValue(kotlin.Function1)(@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull value, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> block)` Iterates over every value stored in this cache by invoking the specified `https://developer.android.com/reference/androidx/collection/SieveCache#forEachValue(kotlin.Function1)` lambda. |
| `final V` | `https://developer.android.com/reference/androidx/collection/SieveCache#get(kotlin.Any)(@https://developer.android.com/reference/androidx/annotation/NonNull K key)` Returns the value for `https://developer.android.com/reference/androidx/collection/SieveCache#get(kotlin.Any)` if it exists in the cache or can be created by `https://developer.android.com/reference/androidx/collection/SieveCache#createValueFromKey()`. |
| `final int` | `https://developer.android.com/reference/androidx/collection/SieveCache#getCapacity()()` Returns the number of entries that can be stored in this cache without requiring internal storage reallocation. |
| `final int` | `https://developer.android.com/reference/androidx/collection/SieveCache#getCount()()` Returns the number of elements held in the cache. |
| `final int` | `https://developer.android.com/reference/androidx/collection/SieveCache#getMaxSize()()` Return the maximum size of the cache before adding new elements causes existing elements to be evicted. |
| `final int` | `https://developer.android.com/reference/androidx/collection/SieveCache#getSize()()` Size of the cache in the unit defined by the implementation of `https://developer.android.com/reference/androidx/collection/SieveCache#sizeOf()` (by default, the number of elements). |
| `int` | `https://developer.android.com/reference/androidx/collection/SieveCache#hashCode()()` Returns the hash code value for this cache. |
| `final boolean` | `https://developer.android.com/reference/androidx/collection/SieveCache#isEmpty()()` Indicates whether this cache is empty. |
| `final boolean` | `https://developer.android.com/reference/androidx/collection/SieveCache#isNotEmpty()()` Returns `true` if this cache is not empty. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#minusAssign(kotlin.Any)(@https://developer.android.com/reference/androidx/annotation/NonNull K key)` Removes the specified `https://developer.android.com/reference/androidx/collection/SieveCache#minusAssign(kotlin.Any)` and its associated value from the map. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#minusAssign(kotlin.Array)(@https://developer.android.com/reference/androidx/annotation/NonNull K[] keys)` Removes the specified `https://developer.android.com/reference/androidx/collection/SieveCache#minusAssign(kotlin.Array)` and their associated value from the map. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#minusAssign(kotlin.collections.Iterable)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Iterable.html<@https://developer.android.com/reference/androidx/annotation/NonNull K> keys)` Removes the specified `https://developer.android.com/reference/androidx/collection/SieveCache#minusAssign(kotlin.collections.Iterable)` and their associated value from the map. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#minusAssign(androidx.collection.ObjectList)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/collection/ObjectList<@https://developer.android.com/reference/androidx/annotation/NonNull K> keys)` Removes the specified `https://developer.android.com/reference/androidx/collection/SieveCache#minusAssign(androidx.collection.ObjectList)` and their associated value from the map. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#minusAssign(androidx.collection.ScatterSet)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/collection/ScatterSet<@https://developer.android.com/reference/androidx/annotation/NonNull K> keys)` Removes the specified `https://developer.android.com/reference/androidx/collection/SieveCache#minusAssign(androidx.collection.ScatterSet)` and their associated value from the map. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#minusAssign(kotlin.sequences.Sequence)(@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.sequences/-sequence/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull K> keys)` Removes the specified `https://developer.android.com/reference/androidx/collection/SieveCache#minusAssign(kotlin.sequences.Sequence)` and their associated value from the map. |
| `final boolean` | `https://developer.android.com/reference/androidx/collection/SieveCache#none()()` Returns `true` if this cache has no entries. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(kotlin.collections.Map)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<@https://developer.android.com/reference/androidx/annotation/NonNull K, @https://developer.android.com/reference/androidx/annotation/NonNull V> from)` Puts all the key/value mappings in the `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(kotlin.collections.Map)` map into this map. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(androidx.collection.ScatterMap)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/collection/ScatterMap<@https://developer.android.com/reference/androidx/annotation/NonNull K, @https://developer.android.com/reference/androidx/annotation/NonNull V> from)` Puts all the key/value mappings in the `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(androidx.collection.ScatterMap)` map into this map. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(androidx.collection.SieveCache)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/collection/SieveCache<@https://developer.android.com/reference/androidx/annotation/NonNull K, @https://developer.android.com/reference/androidx/annotation/NonNull V> from)` Puts all the key/value mappings in the `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(androidx.collection.SieveCache)` map into this map. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(kotlin.Pair)(@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-pair/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull K, @https://developer.android.com/reference/androidx/annotation/NonNull V> pair)` Puts the key/value mapping from the `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(kotlin.Pair)` in this cache, using the first element as the key, and the second element as the value. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(kotlin.Array)(@https://developer.android.com/reference/androidx/annotation/NonNull Pair[] pairs)` Puts all the `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(kotlin.Array)` into this map, using the first component of the pair as the key, and the second component as the value. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(kotlin.collections.Iterable)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Iterable.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-pair/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull K, @https://developer.android.com/reference/androidx/annotation/NonNull V>> pairs)` Puts all the `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(kotlin.collections.Iterable)` into this map, using the first component of the pair as the key, and the second component as the value. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(kotlin.sequences.Sequence)(@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.sequences/-sequence/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-pair/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull K, @https://developer.android.com/reference/androidx/annotation/NonNull V>> pairs)` Puts all the `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(kotlin.sequences.Sequence)` into this map, using the first component of the pair as the key, and the second component as the value. |
| `final V` | `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)(@https://developer.android.com/reference/androidx/annotation/NonNull K key, @https://developer.android.com/reference/androidx/annotation/NonNull V value)` Adds `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` to the cache using the specific `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)`. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#putAll(kotlin.collections.Map)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<@https://developer.android.com/reference/androidx/annotation/NonNull K, @https://developer.android.com/reference/androidx/annotation/NonNull V> from)` Puts all the key/value mappings in the `https://developer.android.com/reference/androidx/collection/SieveCache#putAll(kotlin.collections.Map)` map into this cache. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#putAll(androidx.collection.ScatterMap)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/collection/ScatterMap<@https://developer.android.com/reference/androidx/annotation/NonNull K, @https://developer.android.com/reference/androidx/annotation/NonNull V> from)` Puts all the key/value mappings in the `https://developer.android.com/reference/androidx/collection/SieveCache#putAll(androidx.collection.ScatterMap)` map into this cache. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#putAll(androidx.collection.SieveCache)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/collection/SieveCache<@https://developer.android.com/reference/androidx/annotation/NonNull K, @https://developer.android.com/reference/androidx/annotation/NonNull V> from)` Puts all the key/value mappings in the `https://developer.android.com/reference/androidx/collection/SieveCache#putAll(androidx.collection.SieveCache)` cache into this cache. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#putAll(kotlin.Array)(@https://developer.android.com/reference/androidx/annotation/NonNull Pair[] pairs)` Puts all the `https://developer.android.com/reference/androidx/collection/SieveCache#putAll(kotlin.Array)` into this cache, using the first component of the pair as the key, and the second component as the value. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#putAll(kotlin.collections.Iterable)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Iterable.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-pair/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull K, @https://developer.android.com/reference/androidx/annotation/NonNull V>> pairs)` Puts all the `https://developer.android.com/reference/androidx/collection/SieveCache#putAll(kotlin.collections.Iterable)` into this cache, using the first component of the pair as the key, and the second component as the value. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#putAll(kotlin.sequences.Sequence)(@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.sequences/-sequence/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-pair/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull K, @https://developer.android.com/reference/androidx/annotation/NonNull V>> pairs)` Puts all the `https://developer.android.com/reference/androidx/collection/SieveCache#putAll(kotlin.sequences.Sequence)` into this cache, using the first component of the pair as the key, and the second component as the value. |
| `final V` | `https://developer.android.com/reference/androidx/collection/SieveCache#remove(kotlin.Any)(@https://developer.android.com/reference/androidx/annotation/NonNull K key)` Removes the specified `https://developer.android.com/reference/androidx/collection/SieveCache#remove(kotlin.Any)` and its associated value from the cache. |
| `final boolean` | `https://developer.android.com/reference/androidx/collection/SieveCache#remove(kotlin.Any,kotlin.Any)(@https://developer.android.com/reference/androidx/annotation/NonNull K key, @https://developer.android.com/reference/androidx/annotation/NonNull V value)` Removes the specified `https://developer.android.com/reference/androidx/collection/SieveCache#remove(kotlin.Any,kotlin.Any)` and its associated value from the cache if the associated value equals `https://developer.android.com/reference/androidx/collection/SieveCache#remove(kotlin.Any,kotlin.Any)`. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#removeIf(kotlin.Function2)( @https://developer.android.com/reference/androidx/annotation/NonNull Function2<@https://developer.android.com/reference/androidx/annotation/NonNull K, @https://developer.android.com/reference/androidx/annotation/NonNull V, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html> predicate )` Removes any mapping for which the specified `https://developer.android.com/reference/androidx/collection/SieveCache#removeIf(kotlin.Function2)` returns true. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#resize(kotlin.Int)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 1, to = 2147483646) int maxSize)` Sets the maximum size of the cache to `https://developer.android.com/reference/androidx/collection/SieveCache#resize(kotlin.Int)`, in the unit defined by the implementation of `https://developer.android.com/reference/androidx/collection/SieveCache#sizeOf()`. |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#set(kotlin.Any,kotlin.Any)(@https://developer.android.com/reference/androidx/annotation/NonNull K key, @https://developer.android.com/reference/androidx/annotation/NonNull V value)` Adds `https://developer.android.com/reference/androidx/collection/SieveCache#set(kotlin.Any,kotlin.Any)` to the cache using the specific `https://developer.android.com/reference/androidx/collection/SieveCache#set(kotlin.Any,kotlin.Any)`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/collection/SieveCache#toString()()` |
| `final void` | `https://developer.android.com/reference/androidx/collection/SieveCache#trimToSize(kotlin.Int)(int maxSize)` Remove entries until the total size of the remaining entries is less than or equal to `https://developer.android.com/reference/androidx/collection/SieveCache#trimToSize(kotlin.Int)`. |

## Public constructors

### SieveCache

```
public <K extends Object, V extends Object> SieveCache(
    @IntRange(from = 1, to = 2147483646) int maxSize,
    @IntRange(from = 0, to = 2147483646) int initialCapacity,
    @NonNull Function2<@NonNull key, @NonNull value, @NonNull Integer> sizeOf,
    @NonNull Function1<@NonNull key, V> createValueFromKey,
    @NonNull Function4<@NonNull key, @NonNull oldValue, newValue, @NonNull Boolean, Unit> onEntryRemoved
)
```

Creates a new `https://developer.android.com/reference/androidx/collection/SieveCache`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 1, to = 2147483646) int maxSize` | For caches that do not override `https://developer.android.com/reference/androidx/collection/SieveCache#sizeOf()`, this is the maximum number of entries in the cache. For all other caches, this is the maximum sum of the sizes of the entries in this cache. The maximum size must be strictly greater than 0 and must be less than or equal to `Int.MAX_VALUE - 1`. |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0, to = 2147483646) int initialCapacity` | The initial desired capacity for this cache. The cache will honor this value by guaranteeing its internal structures can hold that many entries without requiring any allocations. The initial capacity can be set to 0. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function2<@https://developer.android.com/reference/androidx/annotation/NonNull key, @https://developer.android.com/reference/androidx/annotation/NonNull value, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Integer.html> sizeOf` | Returns the size of the entry for the specified key and value. The size of an entry cannot change after it was added to the cache, and must be \>= 0. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull key, V> createValueFromKey` | Called after a cache miss to compute a value for the specified key. Returning null from this lambda indicates that no value can be computed. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function4<@https://developer.android.com/reference/androidx/annotation/NonNull key, @https://developer.android.com/reference/androidx/annotation/NonNull oldValue, newValue, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> onEntryRemoved` | Called for entries that have been removed by the user of the cache, or automatically evicted. The lambda is supplied with multiple parameters. The `key` of the entry being removed or evicted. The original value (`oldValue`) of the entry if the entry is being evicted or replaced. The new value (`newValue`) for the key, if it exists. If non-null, the removal was caused by a `put()` or a `set()`, otherwise it was caused by an eviction or a removal. A boolean (`evicted`) set to `true` if the entry was evicted to make space in the cache, or set to `false` if the removal happened on demand or while replacing an existing value with `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)`. |

## Public methods

### all

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

```
public final boolean all(@NonNull Function2<@NonNull K, @NonNull V, @NonNull Boolean> predicate)
```

Returns true if all entries match the given `https://developer.android.com/reference/androidx/collection/SieveCache#all(kotlin.Function2)`.

### any

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

```
public final boolean any()
```

Returns `true` if this cache has at least one entry.

### any

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

```
public final boolean any(@NonNull Function2<@NonNull K, @NonNull V, @NonNull Boolean> predicate)
```

Returns true if at least one entry matches the given `https://developer.android.com/reference/androidx/collection/SieveCache#any(kotlin.Function2)`.

### contains

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

```
public final boolean contains(@NonNull K key)
```

Returns true if the specified `https://developer.android.com/reference/androidx/collection/SieveCache#contains(kotlin.Any)` is present in this cache, false otherwise.

### containsKey

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

```
public final boolean containsKey(@NonNull K key)
```

Returns true if the specified `https://developer.android.com/reference/androidx/collection/SieveCache#containsKey(kotlin.Any)` is present in this cache, false otherwise.

### containsValue

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

```
public final boolean containsValue(@NonNull V value)
```

Returns true if the specified `https://developer.android.com/reference/androidx/collection/SieveCache#containsValue(kotlin.Any)` is present in this hash map, false otherwise.

### count

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

```
public final int count()
```

Returns the number of entries in this cache.

### count

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

```
public final int count(@NonNull Function2<@NonNull K, @NonNull V, @NonNull Boolean> predicate)
```

Returns the number of entries matching the given `https://developer.android.com/reference/androidx/collection/SieveCache#count(kotlin.Function2)`.

### equals

```
public boolean equals(Object other)
```

Compares the specified object `https://developer.android.com/reference/androidx/collection/SieveCache#equals(kotlin.Any)` with this cache for equality. The two objects are considered equal if `https://developer.android.com/reference/androidx/collection/SieveCache#equals(kotlin.Any)`:

- Is a `https://developer.android.com/reference/androidx/collection/SieveCache`

- Has the same `https://developer.android.com/reference/androidx/collection/SieveCache#size()` and `https://developer.android.com/reference/androidx/collection/SieveCache#count()` as this cache

- Contains key/value pairs equal to this cache's pair

### evictAll

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

```
public final void evictAll()
```

Removes all the entries from this cache. Upon each removal, `https://developer.android.com/reference/androidx/collection/SieveCache#onEntryRemoved()` is invoked with the `evicted` parameter set to `true`.

### forEach

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

```
public final void forEach(@NonNull Function2<@NonNull key, @NonNull value, Unit> block)
```

Iterates over every key/value pair stored in this cache by invoking the specified `https://developer.android.com/reference/androidx/collection/SieveCache#forEach(kotlin.Function2)` lambda. The iteration order is not specified.

**NOTE** : Iterating over the content of the cache does *not* mark entries as recently visited, and therefore does not affect which entries get evicted first.

### forEachKey

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

```
public final void forEachKey(@NonNull Function1<@NonNull key, Unit> block)
```

Iterates over every key stored in this cache by invoking the specified `https://developer.android.com/reference/androidx/collection/SieveCache#forEachKey(kotlin.Function1)` lambda.

**NOTE** : Iterating over the content of the cache does *not* mark entries as recently visited, and therefore does not affect which entries get evicted first.

### forEachValue

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

```
public final void forEachValue(@NonNull Function1<@NonNull value, Unit> block)
```

Iterates over every value stored in this cache by invoking the specified `https://developer.android.com/reference/androidx/collection/SieveCache#forEachValue(kotlin.Function1)` lambda.

**NOTE** : Iterating over the content of the cache does *not* mark entries as recently visited, and therefore does not affect which entries get evicted first.

### get

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

```
public final V get(@NonNull K key)
```

Returns the value for `https://developer.android.com/reference/androidx/collection/SieveCache#get(kotlin.Any)` if it exists in the cache or can be created by `https://developer.android.com/reference/androidx/collection/SieveCache#createValueFromKey()`. Return null if a value is not present in the cache and cannot be created.

### getCapacity

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

```
public final int getCapacity()
```

Returns the number of entries that can be stored in this cache without requiring internal storage reallocation.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/collection/SieveCache#count()` |   |

### getCount

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

```
public final int getCount()
```

Returns the number of elements held in the cache.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/collection/SieveCache#capacity()` |   |

### getMaxSize

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

```
public final int getMaxSize()
```

Return the maximum size of the cache before adding new elements causes existing elements to be evicted. The unit of `https://developer.android.com/reference/androidx/collection/SieveCache#maxSize()` is defined by the implementation of `https://developer.android.com/reference/androidx/collection/SieveCache#sizeOf()`. Using the default implementation of `https://developer.android.com/reference/androidx/collection/SieveCache#sizeOf()`, `https://developer.android.com/reference/androidx/collection/SieveCache#maxSize()` indicates the a maximum number of elements.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/collection/SieveCache#size()` |   |

### getSize

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

```
public final int getSize()
```

Size of the cache in the unit defined by the implementation of `https://developer.android.com/reference/androidx/collection/SieveCache#sizeOf()` (by default, the number of elements).

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/collection/SieveCache#maxSize()` |   |

### hashCode

```
public int hashCode()
```

Returns the hash code value for this cache. The hash code the sum of the hash codes of each key/value pair.

### isEmpty

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

```
public final boolean isEmpty()
```

Indicates whether this cache is empty.

### isNotEmpty

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

```
public final boolean isNotEmpty()
```

Returns `true` if this cache is not empty.

### minusAssign

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

```
public final void minusAssign(@NonNull K key)
```

Removes the specified `https://developer.android.com/reference/androidx/collection/SieveCache#minusAssign(kotlin.Any)` and its associated value from the map.

### minusAssign

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

```
public final void minusAssign(@NonNull K[] keys)
```

Removes the specified `https://developer.android.com/reference/androidx/collection/SieveCache#minusAssign(kotlin.Array)` and their associated value from the map.

### minusAssign

```
public final void minusAssign(@NonNull Iterable<@NonNull K> keys)
```

Removes the specified `https://developer.android.com/reference/androidx/collection/SieveCache#minusAssign(kotlin.collections.Iterable)` and their associated value from the map.

### minusAssign

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

```
public final void minusAssign(@NonNull ObjectList<@NonNull K> keys)
```

Removes the specified `https://developer.android.com/reference/androidx/collection/SieveCache#minusAssign(androidx.collection.ObjectList)` and their associated value from the map.

### minusAssign

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

```
public final void minusAssign(@NonNull ScatterSet<@NonNull K> keys)
```

Removes the specified `https://developer.android.com/reference/androidx/collection/SieveCache#minusAssign(androidx.collection.ScatterSet)` and their associated value from the map.

### minusAssign

```
public final void minusAssign(@NonNull Sequence<@NonNull K> keys)
```

Removes the specified `https://developer.android.com/reference/androidx/collection/SieveCache#minusAssign(kotlin.sequences.Sequence)` and their associated value from the map.

### none

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

```
public final boolean none()
```

Returns `true` if this cache has no entries.

### plusAssign

```
public final void plusAssign(@NonNull Map<@NonNull K, @NonNull V> from)
```

Puts all the key/value mappings in the `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(kotlin.collections.Map)` map into this map. Calling this method is equivalent to calling `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for each input pair. See `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for more details about the behavior of each insertion.

### plusAssign

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

```
public final void plusAssign(@NonNull ScatterMap<@NonNull K, @NonNull V> from)
```

Puts all the key/value mappings in the `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(androidx.collection.ScatterMap)` map into this map. Calling this method is equivalent to calling `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for each input pair. See `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for more details about the behavior of each insertion.

### plusAssign

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

```
public final void plusAssign(@NonNull SieveCache<@NonNull K, @NonNull V> from)
```

Puts all the key/value mappings in the `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(androidx.collection.SieveCache)` map into this map. Calling this method is equivalent to calling `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for each input pair. See `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for more details about the behavior of each insertion.

### plusAssign

```
public final void plusAssign(@NonNull Pair<@NonNull K, @NonNull V> pair)
```

Puts the key/value mapping from the `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(kotlin.Pair)` in this cache, using the first element as the key, and the second element as the value. See `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for more details about the insertion behavior.

### plusAssign

```
public final void plusAssign(@NonNull Pair[] pairs)
```

Puts all the `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(kotlin.Array)` into this map, using the first component of the pair as the key, and the second component as the value. Calling this \* method is equivalent to calling `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for each input pair. See `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for more details about the behavior of each insertion.

### plusAssign

```
public final void plusAssign(@NonNull Iterable<@NonNull Pair<@NonNull K, @NonNull V>> pairs)
```

Puts all the `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(kotlin.collections.Iterable)` into this map, using the first component of the pair as the key, and the second component as the value. Calling this \* method is equivalent to calling `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for each input pair. See `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for more details about the behavior of each insertion.

### plusAssign

```
public final void plusAssign(@NonNull Sequence<@NonNull Pair<@NonNull K, @NonNull V>> pairs)
```

Puts all the `https://developer.android.com/reference/androidx/collection/SieveCache#plusAssign(kotlin.sequences.Sequence)` into this map, using the first component of the pair as the key, and the second component as the value. Calling this \* method is equivalent to calling `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for each input pair. See `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for more details about the behavior of each insertion.

### put

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

```
public final V put(@NonNull K key, @NonNull V value)
```

Adds `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` to the cache using the specific `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)`. If `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` is already present in the map, the association is modified and the previously associated value is replaced with `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)`. If `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` is not present, a new entry is added to the map. If an existing value is replaced, `https://developer.android.com/reference/androidx/collection/SieveCache#onEntryRemoved()` will be invoked with the `evicted` parameter set to `false`.

When `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` is added to the cache, `https://developer.android.com/reference/androidx/collection/SieveCache#sizeOf()` is invoked to query its size. If the total size of the cache, including the new value's size, is greater than `https://developer.android.com/reference/androidx/collection/SieveCache#maxSize()`, existing entries will be evicted. On each removal due to an eviction, `https://developer.android.com/reference/androidx/collection/SieveCache#onEntryRemoved()` will be invoked with the `evicted` parameter set to `true`.

Return the previous value associated with the `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)`, or `null` if the key was not present in the cache.

### putAll

```
public final void putAll(@NonNull Map<@NonNull K, @NonNull V> from)
```

Puts all the key/value mappings in the `https://developer.android.com/reference/androidx/collection/SieveCache#putAll(kotlin.collections.Map)` map into this cache. Calling this method is equivalent to calling `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for each input pair. See `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for more details about the behavior of each insertion.

### putAll

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

```
public final void putAll(@NonNull ScatterMap<@NonNull K, @NonNull V> from)
```

Puts all the key/value mappings in the `https://developer.android.com/reference/androidx/collection/SieveCache#putAll(androidx.collection.ScatterMap)` map into this cache. Calling this method is equivalent to calling `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for each input pair. See `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for more details about the behavior of each insertion.

### putAll

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

```
public final void putAll(@NonNull SieveCache<@NonNull K, @NonNull V> from)
```

Puts all the key/value mappings in the `https://developer.android.com/reference/androidx/collection/SieveCache#putAll(androidx.collection.SieveCache)` cache into this cache. Calling this method is equivalent to calling `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for each input pair. See `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for more details about the behavior of each insertion.

### putAll

```
public final void putAll(@NonNull Pair[] pairs)
```

Puts all the `https://developer.android.com/reference/androidx/collection/SieveCache#putAll(kotlin.Array)` into this cache, using the first component of the pair as the key, and the second component as the value. Calling this method is equivalent to calling `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for each input pair. See `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for more details about the behavior of each insertion.

### putAll

```
public final void putAll(@NonNull Iterable<@NonNull Pair<@NonNull K, @NonNull V>> pairs)
```

Puts all the `https://developer.android.com/reference/androidx/collection/SieveCache#putAll(kotlin.collections.Iterable)` into this cache, using the first component of the pair as the key, and the second component as the value. Calling this method is equivalent to calling `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for each input pair. See `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for more details about the behavior of each insertion.

### putAll

```
public final void putAll(@NonNull Sequence<@NonNull Pair<@NonNull K, @NonNull V>> pairs)
```

Puts all the `https://developer.android.com/reference/androidx/collection/SieveCache#putAll(kotlin.sequences.Sequence)` into this cache, using the first component of the pair as the key, and the second component as the value. Calling this method is equivalent to calling `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for each input pair. See `https://developer.android.com/reference/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for more details about the behavior of each insertion.

### remove

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

```
public final V remove(@NonNull K key)
```

Removes the specified `https://developer.android.com/reference/androidx/collection/SieveCache#remove(kotlin.Any)` and its associated value from the cache. If the `https://developer.android.com/reference/androidx/collection/SieveCache#remove(kotlin.Any)` was present in the cache, this function returns the value that was present before removal, otherwise it returns `null`. On successful removal, `https://developer.android.com/reference/androidx/collection/SieveCache#sizeOf()` will be invoked to query the size of the removed element, and `https://developer.android.com/reference/androidx/collection/SieveCache#onEntryRemoved()` will be invoked with the `evicted` parameter set to `false`.

### remove

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

```
public final boolean remove(@NonNull K key, @NonNull V value)
```

Removes the specified `https://developer.android.com/reference/androidx/collection/SieveCache#remove(kotlin.Any,kotlin.Any)` and its associated value from the cache if the associated value equals `https://developer.android.com/reference/androidx/collection/SieveCache#remove(kotlin.Any,kotlin.Any)`. If the `https://developer.android.com/reference/androidx/collection/SieveCache#remove(kotlin.Any,kotlin.Any)` was present in the cache, this function returns true, otherwise it returns false. On successful removal, `https://developer.android.com/reference/androidx/collection/SieveCache#sizeOf()` will be invoked to query the size of the removed element, and `https://developer.android.com/reference/androidx/collection/SieveCache#onEntryRemoved()` will be invoked with the `evicted` parameter set to `false`.

### removeIf

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

```
public final void removeIf(
    @NonNull Function2<@NonNull K, @NonNull V, @NonNull Boolean> predicate
)
```

Removes any mapping for which the specified `https://developer.android.com/reference/androidx/collection/SieveCache#removeIf(kotlin.Function2)` returns true.

### resize

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

```
public final void resize(@IntRange(from = 1, to = 2147483646) int maxSize)
```

Sets the maximum size of the cache to `https://developer.android.com/reference/androidx/collection/SieveCache#resize(kotlin.Int)`, in the unit defined by the implementation of `https://developer.android.com/reference/androidx/collection/SieveCache#sizeOf()`. The size must be strictly greater than 0. If the current total size of the entries in the cache is greater than the new `https://developer.android.com/reference/androidx/collection/SieveCache#resize(kotlin.Int)`, entries will be removed until the total size is less than or equal to `https://developer.android.com/reference/androidx/collection/SieveCache#resize(kotlin.Int)`. Upon each removal, `https://developer.android.com/reference/androidx/collection/SieveCache#onEntryRemoved()` is invoked with the `evicted` parameter set to `true`.

### set

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

```
public final void set(@NonNull K key, @NonNull V value)
```

Adds `https://developer.android.com/reference/androidx/collection/SieveCache#set(kotlin.Any,kotlin.Any)` to the cache using the specific `https://developer.android.com/reference/androidx/collection/SieveCache#set(kotlin.Any,kotlin.Any)`. If `https://developer.android.com/reference/androidx/collection/SieveCache#set(kotlin.Any,kotlin.Any)` is already present in the cache, the association is modified and the previously associated value is replaced with `https://developer.android.com/reference/androidx/collection/SieveCache#set(kotlin.Any,kotlin.Any)`. If `https://developer.android.com/reference/androidx/collection/SieveCache#set(kotlin.Any,kotlin.Any)` is not present, a new entry is added to the map. If an existing value is replaced, `https://developer.android.com/reference/androidx/collection/SieveCache#onEntryRemoved()` will be invoked with the `evicted` parameter set to `false`.

When `https://developer.android.com/reference/androidx/collection/SieveCache#set(kotlin.Any,kotlin.Any)` is added to the cache, `https://developer.android.com/reference/androidx/collection/SieveCache#sizeOf()` is invoked to query its size. If the total size of the cache, including the new value's size, is greater than `https://developer.android.com/reference/androidx/collection/SieveCache#maxSize()`, existing entries will be evicted. On each removal due to an eviction, `https://developer.android.com/reference/androidx/collection/SieveCache#onEntryRemoved()` will be invoked with the `evicted` parameter set to `true`.

### toString

```
public @NonNull String toString()
```

### trimToSize

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

```
public final void trimToSize(int maxSize)
```

Remove entries until the total size of the remaining entries is less than or equal to `https://developer.android.com/reference/androidx/collection/SieveCache#trimToSize(kotlin.Int)`. The size of the entries is defined by the implementation of `https://developer.android.com/reference/androidx/collection/SieveCache#sizeOf()`. Upon each removal, `https://developer.android.com/reference/androidx/collection/SieveCache#onEntryRemoved()` is invoked with the `evicted` parameter set to `true`.

If `https://developer.android.com/reference/androidx/collection/SieveCache#trimToSize(kotlin.Int)` is set to -1 (or any negative value), all entries are removed.