In the API of Google Developer there is a trimToSize() Method, that I can't find / use. How do I clear or reduze the size of my LRU Cache ?
Asked
Active
Viewed 6,418 times
1 Answers
10
public final void evictAll ()
Added in API level 12
Clear the cache, calling entryRemoved(boolean, K, V, V)
on each removed entry.
Use this method.

Triode
- 11,309
- 2
- 38
- 48
-
Thanks a lot. Do you also know how I can remove the halfe of all older objects. I mean clear the cache to the halfe with older objects ? – mcfly soft Feb 17 '14 at 17:43
-
Try calling public final V remove (K key) method so that you can remove a particular entry. Try to call this based on the entry count – Triode Feb 17 '14 at 17:49
-
But I do not know the keys. – mcfly soft Feb 17 '14 at 18:03
-
how you are inserting items to LRUCache? – Triode Feb 17 '14 at 18:07
-
chaotics. depends on the users behaviour and I do not maintain a seperate list of keys. :-( – mcfly soft Feb 17 '14 at 18:10
-
If you not how you can remove it. Just keep a list of keys if you want to get it removed. – Triode Feb 17 '14 at 18:11
-
I guess i'll have to do that. Thanks ! – mcfly soft Feb 17 '14 at 18:57
-
use evictAll() method to remove all the elements – Sam Nov 05 '14 at 20:41
-
`snapshot()` might be of value to anyone looking at this. It returns an LRU ordered list of keys in cache. – j2abro Jun 28 '17 at 13:54
-
@j2abro Thank you, I will update the answer and would be helpful for others. – Triode Jun 28 '17 at 14:53