The Javadoc says:
Returns a view of the entries stored in this cache as a thread-safe map. Modifications made to the map directly affect the cache.
What I'm missing is the information about whether access to the view influences the admission and eviction policies. According to this old related issue it does not:
In Guava's CacheBuilder we added the asMap() view specifically to allow bypassing the cache management routines. There a cache.asMap().get(key) is a peek operation.
This surely makes sense. OTOH the view provides many operations unavailable directly and users may be tempted to use them hoping that they update the access statistics just like direct operations.
For example, I found myself using cache.asMap().putIfAbsent
as my values are functions of the keys, so replacing them is pointless. I'd like it to work exactly as cache.put
in case the entry was absent.