You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2020/10/19 11:09:53 UTC

[GitHub] [sling-org-apache-sling-models-impl] raducotescu commented on a change in pull request #21: SLING-9834 - [Sling Models] Caching bug with reused Servlet requests

raducotescu commented on a change in pull request #21:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/21#discussion_r507661762



##########
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:
       Don't we already know here that there was no cache created for this `adaptable`? If a cache was available, we would have returned the result already - see https://github.com/apache/sling-org-apache-sling-models-impl/pull/21/files#diff-0c273224a9fa6e263f4381c5d4b8145aa2c6c89e75e0b62025eea5efa17edec9R401.

##########
File path: src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
##########
@@ -421,11 +443,7 @@ public boolean isModelClass(@NotNull Class<?> type) {
                         result = createObject(adaptable, modelClass);
 
                         if (result.wasSuccessful() && 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:
       Don't we already know here that there was no cache created for this `adaptable`? If a cache was available, we would have returned the result already - see https://github.com/apache/sling-org-apache-sling-models-impl/pull/21/files#diff-0c273224a9fa6e263f4381c5d4b8145aa2c6c89e75e0b62025eea5efa17edec9R401.




----------------------------------------------------------------
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:
users@infra.apache.org