blob: ca42c683ce4f84ee38fb362676cdbe042088be65 [file]
<html devsite="true">
<head>
<title>LruCache</title>
{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %}
{% include "_shared/_reference-head-tags.html" %}
</head>
<body>
<div itemscope="" itemtype="http://developers.google.com/ReferenceObject">
<meta itemprop="name" content="LruCache">
<meta itemprop="path" content="androidx.collection">
<meta itemprop="property" content="create(kotlin.Any)">
<meta itemprop="property" content="createCount()">
<meta itemprop="property" content="entryRemoved(kotlin.Boolean,kotlin.Any,kotlin.Any,kotlin.Any)">
<meta itemprop="property" content="evictAll()">
<meta itemprop="property" content="evictionCount()">
<meta itemprop="property" content="get(kotlin.Any)">
<meta itemprop="property" content="hitCount()">
<meta itemprop="property" content="maxSize()">
<meta itemprop="property" content="missCount()">
<meta itemprop="property" content="put(kotlin.Any,kotlin.Any)">
<meta itemprop="property" content="putCount()">
<meta itemprop="property" content="remove(kotlin.Any)">
<meta itemprop="property" content="resize(kotlin.Int)">
<meta itemprop="property" content="size()">
<meta itemprop="property" content="sizeOf(kotlin.Any,kotlin.Any)">
<meta itemprop="property" content="snapshot()">
<meta itemprop="property" content="toString()">
<meta itemprop="property" content="trimToSize(kotlin.Int)">
<meta itemprop="language" content="JAVA">
</div>
<div id="header-block">
<div>
<h1>LruCache</h1>
</div>
<div id="metadata-info-block">
<div id="source-link"><a href="https://cs.android.com/search?q=file:androidx/collection/LruCache.kt+class:androidx.collection.LruCache&amp;ss=androidx/platform/frameworks/support" class="external">View Source</a></div>
</div>
</div>
<div id="refdoc-switcher-placeholder"></div>
<p>
<pre>public class <a href="/reference/androidx/collection/LruCache.html">LruCache</a>&lt;K&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>,&nbsp;V&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt;</pre>
</p>
<hr>
<p>Static library version of <code>android.util.LruCache</code>. Used to write apps that run on API levels prior to 12. When running on API level 12 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework SDK documentation for a class overview.</p>
<h2>Summary</h2>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Public constructors</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td>
<div><code>&lt;K&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>,&nbsp;V&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LruCache.html#LruCache(kotlin.Int)">LruCache</a>(@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.ranges/-int-range/index.html">IntRange</a> int&nbsp;maxSize)</code></div>
<p>Creates a new <code><a href="/reference/androidx/collection/LruCache.html">LruCache</a></code></p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Public methods</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>final int</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LruCache.html#createCount()">createCount</a>()</code></div>
<p>Returns the number of times <code><a href="/reference/androidx/collection/LruCache.html#create(kotlin.Any)">create</a></code> returned a value.</p>
</td>
</tr>
<tr>
<td><code>final void</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LruCache.html#evictAll()">evictAll</a>()</code></div>
<p>Clear the cache, calling <code><a href="/reference/androidx/collection/LruCache.html#entryRemoved(kotlin.Boolean,kotlin.Any,kotlin.Any,kotlin.Any)">entryRemoved</a></code> on each removed entry.</p>
</td>
</tr>
<tr>
<td><code>final int</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LruCache.html#evictionCount()">evictionCount</a>()</code></div>
<p>Returns the number of values that have been evicted.</p>
</td>
</tr>
<tr>
<td><code>final V</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LruCache.html#get(kotlin.Any)">get</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> K&nbsp;key)</code></div>
<p>Returns the value for <code><a href="/reference/androidx/collection/LruCache.html#get(kotlin.Any)">key</a></code> if it exists in the cache or can be created by <code><a href="/reference/androidx/collection/LruCache.html#create(kotlin.Any)">create</a></code>.</p>
</td>
</tr>
<tr>
<td><code>final int</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LruCache.html#hitCount()">hitCount</a>()</code></div>
<p>Returns the number of times <code><a href="/reference/androidx/collection/LruCache.html#get(kotlin.Any)">get</a></code> returned a value that was already present in the cache.</p>
</td>
</tr>
<tr>
<td><code>final int</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LruCache.html#maxSize()">maxSize</a>()</code></div>
<p>For caches that do not override <code><a href="/reference/androidx/collection/LruCache.html#sizeOf(kotlin.Any,kotlin.Any)">sizeOf</a></code>, this returns the maximum number of entries in the cache.</p>
</td>
</tr>
<tr>
<td><code>final int</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LruCache.html#missCount()">missCount</a>()</code></div>
<p>Returns the number of times <code><a href="/reference/androidx/collection/LruCache.html#get(kotlin.Any)">get</a></code> returned null or required a new value to be created.</p>
</td>
</tr>
<tr>
<td><code>final V</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LruCache.html#put(kotlin.Any,kotlin.Any)">put</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> K&nbsp;key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> V&nbsp;value)</code></div>
<p>Caches <code><a href="/reference/androidx/collection/LruCache.html#put(kotlin.Any,kotlin.Any)">value</a></code> for <code><a href="/reference/androidx/collection/LruCache.html#put(kotlin.Any,kotlin.Any)">key</a></code>.</p>
</td>
</tr>
<tr>
<td><code>final int</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LruCache.html#putCount()">putCount</a>()</code></div>
<p>Returns the number of times <code><a href="/reference/androidx/collection/LruCache.html#put(kotlin.Any,kotlin.Any)">put</a></code> was called.</p>
</td>
</tr>
<tr>
<td><code>final V</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LruCache.html#remove(kotlin.Any)">remove</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> K&nbsp;key)</code></div>
<p>Removes the entry for <code><a href="/reference/androidx/collection/LruCache.html#remove(kotlin.Any)">key</a></code> if it exists.</p>
</td>
</tr>
<tr>
<td><code>void</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LruCache.html#resize(kotlin.Int)">resize</a>(@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.ranges/-int-range/index.html">IntRange</a> int&nbsp;maxSize)</code></div>
<p>Sets the size of the cache.</p>
</td>
</tr>
<tr>
<td><code>final int</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LruCache.html#size()">size</a>()</code></div>
<p>For caches that do not override <code><a href="/reference/androidx/collection/LruCache.html#sizeOf(kotlin.Any,kotlin.Any)">sizeOf</a></code>, this returns the number of entries in the cache.</p>
</td>
</tr>
<tr>
<td><code>final @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/util/Map.html">Map</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> K,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> V&gt;</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LruCache.html#snapshot()">snapshot</a>()</code></div>
<p>Returns a mutable copy of the current contents of the cache, ordered from least recently accessed to most recently accessed.</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/lang/String.html">String</a></code></td>
<td>
<div><code><a href="/reference/androidx/collection/LruCache.html#toString()">toString</a>()</code></div>
</td>
</tr>
<tr>
<td><code>void</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LruCache.html#trimToSize(kotlin.Int)">trimToSize</a>(int&nbsp;maxSize)</code></div>
<p>Remove the eldest entries until the total of remaining entries is at or below the requested size.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Protected methods</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>V</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LruCache.html#create(kotlin.Any)">create</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> K&nbsp;key)</code></div>
<p>Called after a cache miss to compute a value for the corresponding key.</p>
</td>
</tr>
<tr>
<td><code>void</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LruCache.html#entryRemoved(kotlin.Boolean,kotlin.Any,kotlin.Any,kotlin.Any)">entryRemoved</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;boolean&nbsp;evicted,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> K&nbsp;key,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> V&nbsp;oldValue,<br>&nbsp;&nbsp;&nbsp;&nbsp;V&nbsp;newValue<br>)</code></div>
<p>Called for entries that have been evicted or removed.</p>
</td>
</tr>
<tr>
<td><code>int</code></td>
<td>
<div><code><a href="/reference/androidx/collection/LruCache.html#sizeOf(kotlin.Any,kotlin.Any)">sizeOf</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> K&nbsp;key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> V&nbsp;value)</code></div>
<p>Returns the size of the entry for <code><a href="/reference/androidx/collection/LruCache.html#sizeOf(kotlin.Any,kotlin.Any)">key</a></code> and <code><a href="/reference/androidx/collection/LruCache.html#sizeOf(kotlin.Any,kotlin.Any)">value</a></code> in user-defined units.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="list">
<h2>Public constructors</h2>
<div class="api-item"><a name="LruCache-kotlin.Int-"></a><a name="lrucache"></a>
<div class="api-name-block">
<div>
<h3 id="LruCache(kotlin.Int)">LruCache</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;&lt;K&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>,&nbsp;V&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/collection/LruCache.html#LruCache(kotlin.Int)">LruCache</a>(@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.ranges/-int-range/index.html">IntRange</a> int&nbsp;maxSize)</pre>
<p>Creates a new <code><a href="/reference/androidx/collection/LruCache.html">LruCache</a></code></p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.ranges/-int-range/index.html">IntRange</a> int&nbsp;maxSize</code></td>
<td>
<p>for caches that do not override <code><a href="/reference/androidx/collection/LruCache.html#sizeOf(kotlin.Any,kotlin.Any)">sizeOf</a></code>, 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.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="list">
<h2>Public methods</h2>
<div class="api-item"><a name="createCount--"></a><a name="createcount"></a>
<div class="api-name-block">
<div>
<h3 id="createCount()">createCount</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;int&nbsp;<a href="/reference/androidx/collection/LruCache.html#createCount()">createCount</a>()</pre>
<p>Returns the number of times <code><a href="/reference/androidx/collection/LruCache.html#create(kotlin.Any)">create</a></code> returned a value.</p>
</div>
<div class="api-item"><a name="evictAll--"></a><a name="evictall"></a>
<div class="api-name-block">
<div>
<h3 id="evictAll()">evictAll</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;void&nbsp;<a href="/reference/androidx/collection/LruCache.html#evictAll()">evictAll</a>()</pre>
<p>Clear the cache, calling <code><a href="/reference/androidx/collection/LruCache.html#entryRemoved(kotlin.Boolean,kotlin.Any,kotlin.Any,kotlin.Any)">entryRemoved</a></code> on each removed entry.</p>
</div>
<div class="api-item"><a name="evictionCount--"></a><a name="evictioncount"></a>
<div class="api-name-block">
<div>
<h3 id="evictionCount()">evictionCount</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;int&nbsp;<a href="/reference/androidx/collection/LruCache.html#evictionCount()">evictionCount</a>()</pre>
<p>Returns the number of values that have been evicted.</p>
</div>
<div class="api-item"><a name="get-kotlin.Any-"></a><a name="get"></a>
<div class="api-name-block">
<div>
<h3 id="get(kotlin.Any)">get</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;V&nbsp;<a href="/reference/androidx/collection/LruCache.html#get(kotlin.Any)">get</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> K&nbsp;key)</pre>
<p>Returns the value for <code><a href="/reference/androidx/collection/LruCache.html#get(kotlin.Any)">key</a></code> if it exists in the cache or can be created by <code><a href="/reference/androidx/collection/LruCache.html#create(kotlin.Any)">create</a></code>. If a value was returned, it is moved to the head of the queue. This returns <code>null</code> if a value is not cached and cannot be created.</p>
</div>
<div class="api-item"><a name="hitCount--"></a><a name="hitcount"></a>
<div class="api-name-block">
<div>
<h3 id="hitCount()">hitCount</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;int&nbsp;<a href="/reference/androidx/collection/LruCache.html#hitCount()">hitCount</a>()</pre>
<p>Returns the number of times <code><a href="/reference/androidx/collection/LruCache.html#get(kotlin.Any)">get</a></code> returned a value that was already present in the cache.</p>
</div>
<div class="api-item"><a name="maxSize--"></a><a name="maxsize"></a>
<div class="api-name-block">
<div>
<h3 id="maxSize()">maxSize</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;int&nbsp;<a href="/reference/androidx/collection/LruCache.html#maxSize()">maxSize</a>()</pre>
<p>For caches that do not override <code><a href="/reference/androidx/collection/LruCache.html#sizeOf(kotlin.Any,kotlin.Any)">sizeOf</a></code>, this returns the maximum number of entries in the cache. For all other caches, this returns the maximum sum of the sizes of the entries in this cache.</p>
</div>
<div class="api-item"><a name="missCount--"></a><a name="misscount"></a>
<div class="api-name-block">
<div>
<h3 id="missCount()">missCount</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;int&nbsp;<a href="/reference/androidx/collection/LruCache.html#missCount()">missCount</a>()</pre>
<p>Returns the number of times <code><a href="/reference/androidx/collection/LruCache.html#get(kotlin.Any)">get</a></code> returned null or required a new value to be created.</p>
</div>
<div class="api-item"><a name="put(kotlin.Any, kotlin.Any)"></a><a name="put-kotlin.Any-kotlin.Any-"></a><a name="put"></a>
<div class="api-name-block">
<div>
<h3 id="put(kotlin.Any,kotlin.Any)">put</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;V&nbsp;<a href="/reference/androidx/collection/LruCache.html#put(kotlin.Any,kotlin.Any)">put</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> K&nbsp;key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> V&nbsp;value)</pre>
<p>Caches <code><a href="/reference/androidx/collection/LruCache.html#put(kotlin.Any,kotlin.Any)">value</a></code> for <code><a href="/reference/androidx/collection/LruCache.html#put(kotlin.Any,kotlin.Any)">key</a></code>. The value is moved to the head of the queue.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>V</code></td>
<td>
<p>the previous value mapped by <code><a href="/reference/androidx/collection/LruCache.html#put(kotlin.Any,kotlin.Any)">key</a></code>.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="putCount--"></a><a name="putcount"></a>
<div class="api-name-block">
<div>
<h3 id="putCount()">putCount</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;int&nbsp;<a href="/reference/androidx/collection/LruCache.html#putCount()">putCount</a>()</pre>
<p>Returns the number of times <code><a href="/reference/androidx/collection/LruCache.html#put(kotlin.Any,kotlin.Any)">put</a></code> was called.</p>
</div>
<div class="api-item"><a name="remove-kotlin.Any-"></a><a name="remove"></a>
<div class="api-name-block">
<div>
<h3 id="remove(kotlin.Any)">remove</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;V&nbsp;<a href="/reference/androidx/collection/LruCache.html#remove(kotlin.Any)">remove</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> K&nbsp;key)</pre>
<p>Removes the entry for <code><a href="/reference/androidx/collection/LruCache.html#remove(kotlin.Any)">key</a></code> if it exists.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>V</code></td>
<td>
<p>the previous value mapped by <code><a href="/reference/androidx/collection/LruCache.html#remove(kotlin.Any)">key</a></code>.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="resize-kotlin.Int-"></a><a name="resize"></a>
<div class="api-name-block">
<div>
<h3 id="resize(kotlin.Int)">resize</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;void&nbsp;<a href="/reference/androidx/collection/LruCache.html#resize(kotlin.Int)">resize</a>(@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.ranges/-int-range/index.html">IntRange</a> int&nbsp;maxSize)</pre>
<p>Sets the size of the cache.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.ranges/-int-range/index.html">IntRange</a> int&nbsp;maxSize</code></td>
<td>
<p>The new maximum size.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="size--"></a><a name="size"></a>
<div class="api-name-block">
<div>
<h3 id="size()">size</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;int&nbsp;<a href="/reference/androidx/collection/LruCache.html#size()">size</a>()</pre>
<p>For caches that do not override <code><a href="/reference/androidx/collection/LruCache.html#sizeOf(kotlin.Any,kotlin.Any)">sizeOf</a></code>, this returns the number of entries in the cache. For all other caches, this returns the sum of the sizes of the entries in this cache.</p>
</div>
<div class="api-item"><a name="snapshot--"></a><a name="snapshot"></a>
<div class="api-name-block">
<div>
<h3 id="snapshot()">snapshot</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/util/Map.html">Map</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> K,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> V&gt;&nbsp;<a href="/reference/androidx/collection/LruCache.html#snapshot()">snapshot</a>()</pre>
<p>Returns a mutable copy of the current contents of the cache, ordered from least recently accessed to most recently accessed.</p>
</div>
<div class="api-item"><a name="toString--"></a><a name="tostring"></a>
<div class="api-name-block">
<div>
<h3 id="toString()">toString</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/lang/String.html">String</a>&nbsp;<a href="/reference/androidx/collection/LruCache.html#toString()">toString</a>()</pre>
</div>
<div class="api-item"><a name="trimToSize-kotlin.Int-"></a><a name="trimtosize"></a>
<div class="api-name-block">
<div>
<h3 id="trimToSize(kotlin.Int)">trimToSize</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;void&nbsp;<a href="/reference/androidx/collection/LruCache.html#trimToSize(kotlin.Int)">trimToSize</a>(int&nbsp;maxSize)</pre>
<p>Remove the eldest entries until the total of remaining entries is at or below the requested size.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>int&nbsp;maxSize</code></td>
<td>
<p>the maximum size of the cache before returning. May be -1 to evict even 0-sized elements.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="list">
<h2>Protected methods</h2>
<div class="api-item"><a name="create-kotlin.Any-"></a><a name="create"></a>
<div class="api-name-block">
<div>
<h3 id="create(kotlin.Any)">create</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">protected&nbsp;V&nbsp;<a href="/reference/androidx/collection/LruCache.html#create(kotlin.Any)">create</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> K&nbsp;key)</pre>
<p>Called after a cache miss to compute a value for the corresponding key. Returns the computed value or null if no value can be computed. The default implementation returns null.</p>
<p>The method is called without synchronization: other threads may access the cache while this method is executing.</p>
<p>If a value for <code><a href="/reference/androidx/collection/LruCache.html#create(kotlin.Any)">key</a></code> exists in the cache when this method returns, the created value will be released with <code><a href="/reference/androidx/collection/LruCache.html#entryRemoved(kotlin.Boolean,kotlin.Any,kotlin.Any,kotlin.Any)">entryRemoved</a></code> and discarded. This can occur when multiple threads request the same key at the same time (causing multiple values to be created), or when one thread calls <code><a href="/reference/androidx/collection/LruCache.html#put(kotlin.Any,kotlin.Any)">put</a></code> while another is creating a value for the same key.</p>
</div>
<div class="api-item"><a name="entryRemoved(kotlin.Boolean, kotlin.Any, kotlin.Any, kotlin.Any)"></a><a name="entryRemoved-kotlin.Boolean-kotlin.Any-kotlin.Any-kotlin.Any-"></a><a name="entryremoved"></a>
<div class="api-name-block">
<div>
<h3 id="entryRemoved(kotlin.Boolean,kotlin.Any,kotlin.Any,kotlin.Any)">entryRemoved</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">protected&nbsp;void&nbsp;<a href="/reference/androidx/collection/LruCache.html#entryRemoved(kotlin.Boolean,kotlin.Any,kotlin.Any,kotlin.Any)">entryRemoved</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;boolean&nbsp;evicted,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> K&nbsp;key,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> V&nbsp;oldValue,<br>&nbsp;&nbsp;&nbsp;&nbsp;V&nbsp;newValue<br>)</pre>
<p>Called for entries that have been evicted or removed. This method is invoked when a value is evicted to make space, removed by a call to <code><a href="/reference/androidx/collection/LruCache.html#remove(kotlin.Any)">remove</a></code>, or replaced by a call to <code><a href="/reference/androidx/collection/LruCache.html#put(kotlin.Any,kotlin.Any)">put</a></code>. The default implementation does nothing.</p>
<p>The method is called without synchronization: other threads may access the cache while this method is executing.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>boolean&nbsp;evicted</code></td>
<td>
<p><code>true</code> if the entry is being removed to make space, <code>false</code> if the removal was caused by a <code><a href="/reference/androidx/collection/LruCache.html#put(kotlin.Any,kotlin.Any)">put</a></code> or <code><a href="/reference/androidx/collection/LruCache.html#remove(kotlin.Any)">remove</a></code>.</p>
</td>
</tr>
<tr>
<td><code>V&nbsp;newValue</code></td>
<td>
<p>the new value for <code><a href="/reference/androidx/collection/LruCache.html#entryRemoved(kotlin.Boolean,kotlin.Any,kotlin.Any,kotlin.Any)">key</a></code>, if it exists. If non-null, this removal was caused by a <code><a href="/reference/androidx/collection/LruCache.html#put(kotlin.Any,kotlin.Any)">put</a></code>. Otherwise it was caused by an eviction or a <code><a href="/reference/androidx/collection/LruCache.html#remove(kotlin.Any)">remove</a></code>.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="sizeOf(kotlin.Any, kotlin.Any)"></a><a name="sizeOf-kotlin.Any-kotlin.Any-"></a><a name="sizeof"></a>
<div class="api-name-block">
<div>
<h3 id="sizeOf(kotlin.Any,kotlin.Any)">sizeOf</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">protected&nbsp;int&nbsp;<a href="/reference/androidx/collection/LruCache.html#sizeOf(kotlin.Any,kotlin.Any)">sizeOf</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> K&nbsp;key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> V&nbsp;value)</pre>
<p>Returns the size of the entry for <code><a href="/reference/androidx/collection/LruCache.html#sizeOf(kotlin.Any,kotlin.Any)">key</a></code> and <code><a href="/reference/androidx/collection/LruCache.html#sizeOf(kotlin.Any,kotlin.Any)">value</a></code> in user-defined units. The default implementation returns 1 so that size is the number of entries and max size is the maximum number of entries.</p>
<p>An entry's size must not change while it is in the cache.</p>
</div>
</div>
</body>
</html>