-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refine WebJarVersionLocator
caching
#8
Comments
I'm not totally clear on what Also worth noting that |
I've implemented the And improved the caching to only cache the version which is the part that is loaded from the classpath. |
Also added caching for missing lookups. Full change: |
It is an HTTP request to resource location cache, but with additional features, see |
I've read through that and I'm still not sure how it gets used in relation to the locator. I think in Spring you have something that makes it so users can just make a request to FWIW, I don't recommend people use those versionless URLs as they don't support good client side caching. |
I have checked on my repro and I can confirm that I understand your recommandation, but the WebJars integration in Spring is part of an extensive static web resource handling where Spring users can manage caching, version resolution and other features, so that kind of concern will be managed outside |
Also see
|
Thanks for the details on that and for confirming that One other path I'm concerned about is usage from templating like Thymeleaf. I'm not sure if it'd be typical to inject something from |
Good point, indeed with this new impl Do you want to release a last |
Cool. Releasing |
Works as expected in Spring Framework tests and my demo app. |
As pointed out by @vpavic here,
WebJarCache
could probably be removed. I suggest we replace it byjava.util.concurrent.ConcurrentMap
interface and update the logic to useConcurrentMap#computeIfAbsent
instead ofWebJarCache#get
andWebJarCache#put
.Also Spring has already its own caching mechanism enabled via
ResourceChainRegistration
(enabled by default with Spring Boot), so Spring likely do not want a 2nd caching mechanism inWebJarVersionLocator
(in order to avoid wasting memory).My proposal is to refine
WebJarVersionLocator
constructors with:WebJarVersionLocator()
default constructor that does not use any cachingWebJarVersionLocator(ConcurrentMap concurrentMap)
which allows to use caching withnew WebJarVersionLocator(new ConcurrentHashMap())
Alternatively, you could have:
WebJarVersionLocator()
default constructor that uses a cache based onConcurrentHashMap
WebJarVersionLocator(boolean cacheEnabled)
that can allow Spring to disable cachingWebJarVersionLocator(ConcurrentMap concurrentMap)
that allows to pass a customConcurrentMap
instance.Or:
WebJarVersionLocator()
default constructor that uses a cache based onConcurrentHashMap
WebJarVersionLocator(@Nullable ConcurrentMap concurrentMap)
which allows to disable caching with anull
parameter.Maybe the last proposal is better?
The text was updated successfully, but these errors were encountered: