thomasmueller commented on code in PR #3176:
URL: https://github.com/apache/jackrabbit-oak/pull/3176#discussion_r4185045247


##########
oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheMetadata.java:
##########
@@ -128,30 +137,48 @@ void clear() {
         metadataMap.clear();
     }
 
-    private MetadataEntry getOrCreate(K key, boolean readFromPersistentCache) {
+    private MetadataEntry getOrCreate(K key, V value, boolean 
readFromPersistentCache) {
         if (!enabled) {
             return null;
         }
-        MetadataEntry metadata = metadataMap.get(key);
-        if (metadata == null) {
-            MetadataEntry newEntry = new 
MetadataEntry(readFromPersistentCache);
-            MetadataEntry oldEntry = metadataMap.putIfAbsent(key, newEntry);
-            metadata = oldEntry == null ? newEntry : oldEntry;
-        }
-        return metadata;
+        MetadataEntry existing = metadataMap.get(key);
+        if (existing != null && existing.isFor(value)) {
+            return existing;
+        }
+        if (existing == null) {
+            MetadataEntry created = new MetadataEntry(value, 
readFromPersistentCache);
+            existing = metadataMap.putIfAbsent(key, created);
+            if (existing == null) {
+                return created;
+            }
+            if (existing.isFor(value)) {
+                return existing;
+            }
+        }
+        return metadataMap.compute(key, (k, metadata) ->
+                metadata != null && metadata.isFor(value)
+                        ? metadata
+                        : new MetadataEntry(value, readFromPersistentCache));
     }
 
 
     static class MetadataEntry {
 
         private final AtomicLong accessCount = new AtomicLong();
 
+        private final Object value;
+

Review Comment:
   If we add the value (in addition to the key) to the MetadataEntry, then this 
becomes a full key-value pair.
   
   If the value can be large (and I assume it can be large), then this can 
consume a lot of memory. The user of this class, the CacheMetadata, does not 
actually use it as a cache but as a map. So in addition to the (small) keys 
this change means we also retain the complete key + value pair.
   
   ... I don't think that's the intention of CacheMetadata class ...



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to