Affects: 5.1.6
I'm using a custom LruCache based on LinkedHashMap.removeEldestEntry and I ran a search in this repository to see if such a thing is already provided to discover there is a nice MimeTypeUtils.ConcurrentLruCache, but it's private.
Is there a chance to extract it somewhere else and make it public?
Comment From: sbrannen
Depending on whether that implementation is made public and whether it gets an extension point for "on removal", it could potentially replace the org.springframework.test.context.cache.DefaultContextCache.LruCache as well.
Comment From: bclozel
Hi @andrei-ivanov The team discussed this issue and we came to the conclusion that we don't want to provide such a feature in our public API, for the following reasons:
- We provided collection-related implementation in the past, and we missed quite a few subtleties in their implementations; that required maintenance work for something we're not really in the business of in the first place (a lot of libraries provide efficient, configurable, collection implementations).
- Extracting it would mean making it more general, applicable to more use cases and add more features. In the short term, reusing it for our own needs in the various places where we have such things is likely to make local performance worse. Each local implementation is really tailored for the case at hand.
In my opinion, libraries such as Caffeine offer other options such as Least Frequently Used cache, which is interesting if unlike Spring Framework, you can afford a mandatory dependency. Thanks!
Comment From: jhoeller
As part of #24197, we now got a public version of ConcurrentLruCache, so this issue is indeed now resolved for inclusion in 5.3. In the meantime, I feel confident enough to make that class public since it got quite a bit of feedback, and it's a clean solution to the problem in NamedParameterJdbcTemplate. That said, this is still mostly for internal use in the framework, as all the utilities in org.springframework.util, so use it at your own risk :-)
Comment From: jhoeller
Freshly closing this ticket with a different resolution.