Current eviction algorithm for maps is quite lazy. It looks like expired objects are evicted only when the data structure is accessed.
For example, the map from addresses to indexers defined as:
ConcurrentMap<Address, Indexer> indexers = new MapMaker()
.expireAfterAccess( EXPIRATION, TimeUnit.SECONDS)
.evictionListener( new IndexEvicted())
.makeMap();
leads to quite surprising pattern: while containsKey()
for the given address returns false, immediately after that indexer for that address is evicted.
What would be the recommended approach to make the clean up process more real-time? I.e. to remove the objects close to the actual expiration time.
Update: I'd like to more clarify what I mean by real-time. For the example above, EXPIRATION being 10 seconds, I'd like to see the inserted object evicted in 10 seconds after last access. That is not happening now - the map must be used somehow to start the eviction. If the map is completely unused, the object can stay there for years.