I just found out about Guava Caching, and all the examples that I see are using map, key, and value.
Is there any way to use guava cache for an ArrayList?
I have an ArrayList that has elements, each element has 60 seconds to live, after that it should be removed, I appreciate any suggestions.
And is it possible to trigger a method after removal of each element? For example, if a number gets removed from the list I need to recalculate the average again.
Guava Cache is designed to be queried by key. However, you could use index of your
ArrayList
as a key or choose some unique property of the object to be the key (though as I understand, you need the values to be stored in the order they were added).Yes, when building your
Cache<K, V>
, setRemovalListener<K,V>
.For example: