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.