# 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)

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  class SieveCache<K : Any, V : Any>
  ```

*** ** * ** ***

`https://developer.android.com/reference/kotlin/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/kotlin/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/kotlin/androidx/collection/LruCache`, `https://developer.android.com/reference/kotlin/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/kotlin/androidx/collection/SieveCache#get(kotlin.Any)` prevents that entry from becoming an eviction candidate. In practice, `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache` offers better hit ratio compared to `https://developer.android.com/reference/kotlin/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/kotlin/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/kotlin/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/kotlin/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/kotlin/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/kotlin/androidx/collection/SieveCache` can hold a maximum of `Int.MAX_VALUE - 1` entries, independent of their computed size.

## Summary

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

| ### Public functions |
|---|---|---|
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#all(kotlin.Function2)(predicate: (K, V) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Returns true if all entries match the given `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#all(kotlin.Function2)`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#any()()` Returns `true` if this cache has at least one entry. | Cmn |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#any(kotlin.Function2)(predicate: (K, V) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Returns true if at least one entry matches the given `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#any(kotlin.Function2)`. | Cmn |
| `operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#contains(kotlin.Any)(key: K)` Returns true if the specified `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#contains(kotlin.Any)` is present in this cache, false otherwise. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#containsKey(kotlin.Any)(key: K)` Returns true if the specified `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#containsKey(kotlin.Any)` is present in this cache, false otherwise. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#containsValue(kotlin.Any)(value: V)` Returns true if the specified `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#containsValue(kotlin.Any)` is present in this hash map, false otherwise. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#count()()` Returns the number of entries in this cache. | Cmn |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#count(kotlin.Function2)(predicate: (K, V) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Returns the number of entries matching the given `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#count(kotlin.Function2)`. | Cmn |
| `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#equals(kotlin.Any)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` Compares the specified object `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#equals(kotlin.Any)` with this cache for equality. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#evictAll()()` Removes all the entries from this cache. | Cmn |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#forEach(kotlin.Function2)(block: (key, value) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Iterates over every key/value pair stored in this cache by invoking the specified `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#forEach(kotlin.Function2)` lambda. | Cmn |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#forEachKey(kotlin.Function1)(block: (key) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Iterates over every key stored in this cache by invoking the specified `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#forEachKey(kotlin.Function1)` lambda. | Cmn |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#forEachValue(kotlin.Function1)(block: (value) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Iterates over every value stored in this cache by invoking the specified `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#forEachValue(kotlin.Function1)` lambda. | Cmn |
| `operator V?` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#get(kotlin.Any)(key: K)` Returns the value for `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#get(kotlin.Any)` if it exists in the cache or can be created by `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#createValueFromKey()`. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#hashCode()()` Returns the hash code value for this cache. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#isEmpty()()` Indicates whether this cache is empty. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#isNotEmpty()()` Returns `true` if this cache is not empty. | Cmn |
| `inline operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#minusAssign(kotlin.Any)(key: K)` Removes the specified `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#minusAssign(kotlin.Any)` and its associated value from the map. | Cmn |
| `inline operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#minusAssign(kotlin.Array)(keys: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<K>)` Removes the specified `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#minusAssign(kotlin.Array)` and their associated value from the map. | Cmn |
| `inline operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#minusAssign(kotlin.collections.Iterable)(keys: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterable/index.html<K>)` Removes the specified `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#minusAssign(kotlin.collections.Iterable)` and their associated value from the map. | Cmn |
| `inline operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#minusAssign(androidx.collection.ObjectList)(keys: https://developer.android.com/reference/kotlin/androidx/collection/ObjectList<K>)` Removes the specified `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#minusAssign(androidx.collection.ObjectList)` and their associated value from the map. | Cmn |
| `inline operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#minusAssign(androidx.collection.ScatterSet)(keys: https://developer.android.com/reference/kotlin/androidx/collection/ScatterSet<K>)` Removes the specified `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#minusAssign(androidx.collection.ScatterSet)` and their associated value from the map. | Cmn |
| `inline operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#minusAssign(kotlin.sequences.Sequence)(keys: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.sequences/-sequence/index.html<K>)` Removes the specified `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#minusAssign(kotlin.sequences.Sequence)` and their associated value from the map. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#none()()` Returns `true` if this cache has no entries. | Cmn |
| `inline operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#plusAssign(kotlin.collections.Map)(from: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<K, V>)` Puts all the key/value mappings in the `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#plusAssign(kotlin.collections.Map)` map into this map. | Cmn |
| `inline operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#plusAssign(androidx.collection.ScatterMap)(from: https://developer.android.com/reference/kotlin/androidx/collection/ScatterMap<K, V>)` Puts all the key/value mappings in the `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#plusAssign(androidx.collection.ScatterMap)` map into this map. | Cmn |
| `inline operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#plusAssign(androidx.collection.SieveCache)(from: https://developer.android.com/reference/kotlin/androidx/collection/SieveCache<K, V>)` Puts all the key/value mappings in the `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#plusAssign(androidx.collection.SieveCache)` map into this map. | Cmn |
| `inline operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#plusAssign(kotlin.Pair)(pair: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-pair/index.html<K, V>)` Puts the key/value mapping from the `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#plusAssign(kotlin.Pair)` in this cache, using the first element as the key, and the second element as the value. | Cmn |
| `inline operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#plusAssign(kotlin.Array)(pairs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-pair/index.html<K, V>>)` Puts all the `https://developer.android.com/reference/kotlin/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. | Cmn |
| `inline operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#plusAssign(kotlin.collections.Iterable)(pairs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterable/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-pair/index.html<K, V>>)` Puts all the `https://developer.android.com/reference/kotlin/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. | Cmn |
| `inline operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#plusAssign(kotlin.sequences.Sequence)(pairs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.sequences/-sequence/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-pair/index.html<K, V>>)` Puts all the `https://developer.android.com/reference/kotlin/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. | Cmn |
| `V?` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)(key: K, value: V)` Adds `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` to the cache using the specific `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#putAll(kotlin.collections.Map)(from: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<K, V>)` Puts all the key/value mappings in the `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#putAll(kotlin.collections.Map)` map into this cache. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#putAll(androidx.collection.ScatterMap)(from: https://developer.android.com/reference/kotlin/androidx/collection/ScatterMap<K, V>)` Puts all the key/value mappings in the `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#putAll(androidx.collection.ScatterMap)` map into this cache. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#putAll(androidx.collection.SieveCache)(from: https://developer.android.com/reference/kotlin/androidx/collection/SieveCache<K, V>)` Puts all the key/value mappings in the `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#putAll(androidx.collection.SieveCache)` cache into this cache. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#putAll(kotlin.Array)(pairs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-pair/index.html<K, V>>)` Puts all the `https://developer.android.com/reference/kotlin/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. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#putAll(kotlin.collections.Iterable)(pairs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterable/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-pair/index.html<K, V>>)` Puts all the `https://developer.android.com/reference/kotlin/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. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#putAll(kotlin.sequences.Sequence)(pairs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.sequences/-sequence/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-pair/index.html<K, V>>)` Puts all the `https://developer.android.com/reference/kotlin/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. | Cmn |
| `V?` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#remove(kotlin.Any)(key: K)` Removes the specified `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#remove(kotlin.Any)` and its associated value from the cache. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#remove(kotlin.Any,kotlin.Any)(key: K, value: V)` Removes the specified `https://developer.android.com/reference/kotlin/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/kotlin/androidx/collection/SieveCache#remove(kotlin.Any,kotlin.Any)`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#removeIf(kotlin.Function2)(predicate: (K, V) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Removes any mapping for which the specified `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#removeIf(kotlin.Function2)` returns true. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#resize(kotlin.Int)(maxSize: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1, to = 2147483646) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the maximum size of the cache to `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#resize(kotlin.Int)`, in the unit defined by the implementation of `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#sizeOf()`. | Cmn |
| `inline operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#set(kotlin.Any,kotlin.Any)(key: K, value: V)` Adds `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#set(kotlin.Any,kotlin.Any)` to the cache using the specific `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#set(kotlin.Any,kotlin.Any)`. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#toString()()` | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#trimToSize(kotlin.Int)(maxSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Remove entries until the total size of the remaining entries is less than or equal to `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#trimToSize(kotlin.Int)`. | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#capacity()` Returns the number of entries that can be stored in this cache without requiring internal storage reallocation. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#count()` Returns the number of elements held in the cache. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#maxSize()` Return the maximum size of the cache before adding new elements causes existing elements to be evicted. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#size()` Size of the cache in the unit defined by the implementation of `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#sizeOf()` (by default, the number of elements). | Cmn |

## Public constructors

### SieveCache

Cmn

```
<K : Any, V : Any> SieveCache(
    maxSize: @IntRange(from = 1, to = 2147483646) Int,
    initialCapacity: @IntRange(from = 0, to = 2147483646) Int = DefaultScatterCapacity,
    sizeOf: (key, value) -> Int = { _, _ -> 1 },
    createValueFromKey: (key) -> V? = { null },
    onEntryRemoved: (key, oldValue, newValue?, evicted: Boolean) -> Unit = { _, _, _, _ ->
        }
)
```

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

| Parameters |
|---|---|
| `maxSize: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1, to = 2147483646) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | For caches that do not override `https://developer.android.com/reference/kotlin/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`. |
| `initialCapacity: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 2147483646) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = DefaultScatterCapacity` | 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. |
| `sizeOf: (key, value) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = { _, _ -> 1 }` | 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. |
| `createValueFromKey: (key) -> V? = { null }` | 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. |
| `onEntryRemoved: (key, oldValue, newValue?, evicted: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html = { _, _, _, _ -> }` | 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/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)`. |

## Public functions

### all

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

```
inline fun all(predicate: (K, V) -> Boolean): Boolean
```

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

### any

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

```
fun any(): Boolean
```

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

### any

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

```
inline fun any(predicate: (K, V) -> Boolean): Boolean
```

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

### contains

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

```
operator fun contains(key: K): Boolean
```

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

### containsKey

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

```
fun containsKey(key: K): Boolean
```

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

### containsValue

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

```
fun containsValue(value: V): Boolean
```

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

### count

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

```
fun count(): Int
```

Returns the number of entries in this cache.

### count

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

```
inline fun count(predicate: (K, V) -> Boolean): Int
```

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

### equals

Cmn

```
open operator fun equals(other: Any?): Boolean
```

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

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

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

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

### evictAll

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

```
fun evictAll(): Unit
```

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

### forEach

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

```
inline fun forEach(block: (key, value) -> Unit): Unit
```

Iterates over every key/value pair stored in this cache by invoking the specified `https://developer.android.com/reference/kotlin/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

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

```
inline fun forEachKey(block: (key) -> Unit): Unit
```

Iterates over every key stored in this cache by invoking the specified `https://developer.android.com/reference/kotlin/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

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

```
inline fun forEachValue(block: (value) -> Unit): Unit
```

Iterates over every value stored in this cache by invoking the specified `https://developer.android.com/reference/kotlin/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

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

```
operator fun get(key: K): V?
```

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

### hashCode

Cmn

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

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

### isEmpty

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

```
fun isEmpty(): Boolean
```

Indicates whether this cache is empty.

### isNotEmpty

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

```
fun isNotEmpty(): Boolean
```

Returns `true` if this cache is not empty.

### minusAssign

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

```
inline operator fun minusAssign(key: K): Unit
```

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

### minusAssign

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

```
inline operator fun minusAssign(keys: Array<K>): Unit
```

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

### minusAssign

Cmn

```
inline operator fun minusAssign(keys: Iterable<K>): Unit
```

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

### minusAssign

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

```
inline operator fun minusAssign(keys: ObjectList<K>): Unit
```

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

### minusAssign

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

```
inline operator fun minusAssign(keys: ScatterSet<K>): Unit
```

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

### minusAssign

Cmn

```
inline operator fun minusAssign(keys: Sequence<K>): Unit
```

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

### none

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

```
fun none(): Boolean
```

Returns `true` if this cache has no entries.

### plusAssign

Cmn

```
inline operator fun plusAssign(from: Map<K, V>): Unit
```

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

### plusAssign

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

```
inline operator fun plusAssign(from: ScatterMap<K, V>): Unit
```

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

### plusAssign

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

```
inline operator fun plusAssign(from: SieveCache<K, V>): Unit
```

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

### plusAssign

Cmn

```
inline operator fun plusAssign(pair: Pair<K, V>): Unit
```

Puts the key/value mapping from the `https://developer.android.com/reference/kotlin/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/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for more details about the insertion behavior.

### plusAssign

Cmn

```
inline operator fun plusAssign(pairs: Array<Pair<K, V>>): Unit
```

Puts all the `https://developer.android.com/reference/kotlin/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/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for each input pair. See `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for more details about the behavior of each insertion.

### plusAssign

Cmn

```
inline operator fun plusAssign(pairs: Iterable<Pair<K, V>>): Unit
```

Puts all the `https://developer.android.com/reference/kotlin/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/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for each input pair. See `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for more details about the behavior of each insertion.

### plusAssign

Cmn

```
inline operator fun plusAssign(pairs: Sequence<Pair<K, V>>): Unit
```

Puts all the `https://developer.android.com/reference/kotlin/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/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for each input pair. See `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for more details about the behavior of each insertion.

### put

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

```
fun put(key: K, value: V): V?
```

Adds `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` to the cache using the specific `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)`. If `https://developer.android.com/reference/kotlin/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/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)`. If `https://developer.android.com/reference/kotlin/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/kotlin/androidx/collection/SieveCache#onEntryRemoved()` will be invoked with the `evicted` parameter set to `false`.

When `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` is added to the cache, `https://developer.android.com/reference/kotlin/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/kotlin/androidx/collection/SieveCache#maxSize()`, existing entries will be evicted. On each removal due to an eviction, `https://developer.android.com/reference/kotlin/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/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)`, or `null` if the key was not present in the cache.

### putAll

Cmn

```
fun putAll(from: Map<K, V>): Unit
```

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

### putAll

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

```
fun putAll(from: ScatterMap<K, V>): Unit
```

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

### putAll

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

```
fun putAll(from: SieveCache<K, V>): Unit
```

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

### putAll

Cmn

```
fun putAll(pairs: Array<Pair<K, V>>): Unit
```

Puts all the `https://developer.android.com/reference/kotlin/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/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for each input pair. See `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for more details about the behavior of each insertion.

### putAll

Cmn

```
fun putAll(pairs: Iterable<Pair<K, V>>): Unit
```

Puts all the `https://developer.android.com/reference/kotlin/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/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for each input pair. See `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for more details about the behavior of each insertion.

### putAll

Cmn

```
fun putAll(pairs: Sequence<Pair<K, V>>): Unit
```

Puts all the `https://developer.android.com/reference/kotlin/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/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for each input pair. See `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#put(kotlin.Any,kotlin.Any)` for more details about the behavior of each insertion.

### remove

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

```
fun remove(key: K): V?
```

Removes the specified `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#remove(kotlin.Any)` and its associated value from the cache. If the `https://developer.android.com/reference/kotlin/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/kotlin/androidx/collection/SieveCache#sizeOf()` will be invoked to query the size of the removed element, and `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#onEntryRemoved()` will be invoked with the `evicted` parameter set to `false`.

### remove

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

```
fun remove(key: K, value: V): Boolean
```

Removes the specified `https://developer.android.com/reference/kotlin/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/kotlin/androidx/collection/SieveCache#remove(kotlin.Any,kotlin.Any)`. If the `https://developer.android.com/reference/kotlin/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/kotlin/androidx/collection/SieveCache#sizeOf()` will be invoked to query the size of the removed element, and `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#onEntryRemoved()` will be invoked with the `evicted` parameter set to `false`.

### removeIf

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

```
fun removeIf(predicate: (K, V) -> Boolean): Unit
```

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

### resize

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

```
fun resize(maxSize: @IntRange(from = 1, to = 2147483646) Int): Unit
```

Sets the maximum size of the cache to `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#resize(kotlin.Int)`, in the unit defined by the implementation of `https://developer.android.com/reference/kotlin/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/kotlin/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/kotlin/androidx/collection/SieveCache#resize(kotlin.Int)`. Upon each removal, `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#onEntryRemoved()` is invoked with the `evicted` parameter set to `true`.

### set

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

```
inline operator fun set(key: K, value: V): Unit
```

Adds `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#set(kotlin.Any,kotlin.Any)` to the cache using the specific `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#set(kotlin.Any,kotlin.Any)`. If `https://developer.android.com/reference/kotlin/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/kotlin/androidx/collection/SieveCache#set(kotlin.Any,kotlin.Any)`. If `https://developer.android.com/reference/kotlin/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/kotlin/androidx/collection/SieveCache#onEntryRemoved()` will be invoked with the `evicted` parameter set to `false`.

When `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#set(kotlin.Any,kotlin.Any)` is added to the cache, `https://developer.android.com/reference/kotlin/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/kotlin/androidx/collection/SieveCache#maxSize()`, existing entries will be evicted. On each removal due to an eviction, `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#onEntryRemoved()` will be invoked with the `evicted` parameter set to `true`.

### toString

Cmn

```
open fun toString(): String
```

### trimToSize

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

```
fun trimToSize(maxSize: Int): Unit
```

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

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

## Public properties

### capacity

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

```
val capacity: Int
```

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

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

### count

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

```
val count: Int
```

Returns the number of elements held in the cache.

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

### maxSize

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

```
val maxSize: Int
```

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/kotlin/androidx/collection/SieveCache#maxSize()` is defined by the implementation of `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#sizeOf()`. Using the default implementation of `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#sizeOf()`, `https://developer.android.com/reference/kotlin/androidx/collection/SieveCache#maxSize()` indicates the a maximum number of elements.

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

### size

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

```
val size: Int
```

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

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