raducotescu commented on a change in pull request #21:
URL:
https://github.com/apache/sling-org-apache-sling-models-impl/pull/21#discussion_r507719558
##########
File path: src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
##########
@@ -404,11 +430,7 @@ public boolean isModelClass(@NotNull Class<?> type) {
ModelType model = (ModelType)
Proxy.newProxyInstance(modelClass.getType().getClassLoader(), new Class<?>[] {
modelClass.getType() }, handlerResult.getValue());
if (modelAnnotation.cache()) {
- Map<Class<?>, SoftReference<Object>>
adaptableCache = adapterCache.get(cacheKey);
- if (adaptableCache == null) {
- adaptableCache =
Collections.synchronizedMap(new WeakHashMap<Class<?>, SoftReference<Object>>());
- adapterCache.put(cacheKey, adaptableCache);
- }
+ Map<Class<?>, SoftReference<Object>>
adaptableCache = getOrCreateCache(adaptable);
Review comment:
I think my question was not clear enough. I'm saying that if the
`modelAnnotation#cache` returns `true`, we can already create the cache for the
`adaptable` at
https://github.com/apache/sling-org-apache-sling-models-impl/pull/21/files#diff-0c273224a9fa6e263f4381c5d4b8145aa2c6c89e75e0b62025eea5efa17edec9R401,
using `getOrCreate`.
Further down, you just need to populate the cache. I think the `getCache`
and `getOrCreate` should be merged and make the code simpler to read.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]