Is there some collection implementation supporting expiration of the elements.
For example:
Collection<User> cachedUsers = new ExpirableList<User>(10000);
where
public ExpirableList(final long timeout){...}
And after given time (10000ms
in this particular example), added elements will be removed from the collection. By using this, we will prevent overflow of our cachedUsers
collection.
Yes, Guava supports a cache with timed expiration. See Guava Explained's page on caches.
An alternative is an LRU (least-recently used) cache that disposes of the oldest accessed element when a new element is inserted.
It's not really clear how you're trying to use the collection, but Guava's CacheBuilder
may help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With