You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2023/12/11 09:20:08 UTC

(maven-resolver) branch master updated: [MRESOLVER-450] Enhance RepositoryCache (#392)

This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git


The following commit(s) were added to refs/heads/master by this push:
     new 5bc30c3b [MRESOLVER-450] Enhance RepositoryCache (#392)
5bc30c3b is described below

commit 5bc30c3be0a163ee4177c6beeb29e9b93084b1f7
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Mon Dec 11 10:20:03 2023 +0100

    [MRESOLVER-450] Enhance RepositoryCache (#392)
    
    Enhance RepositoryCache
    
    ---
    
    https://issues.apache.org/jira/browse/MRESOLVER-450
---
 .../java/org/eclipse/aether/DefaultRepositoryCache.java    |  9 +++++++--
 .../src/main/java/org/eclipse/aether/RepositoryCache.java  | 14 ++++++++++++++
 pom.xml                                                    |  1 +
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/DefaultRepositoryCache.java b/maven-resolver-api/src/main/java/org/eclipse/aether/DefaultRepositoryCache.java
index de8c4dc9..e0f6d505 100644
--- a/maven-resolver-api/src/main/java/org/eclipse/aether/DefaultRepositoryCache.java
+++ b/maven-resolver-api/src/main/java/org/eclipse/aether/DefaultRepositoryCache.java
@@ -18,8 +18,8 @@
  */
 package org.eclipse.aether;
 
-import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Supplier;
 
 /**
  * A simplistic repository cache backed by a thread-safe map. The simplistic nature of this cache makes it only suitable
@@ -27,7 +27,7 @@ import java.util.concurrent.ConcurrentHashMap;
  */
 public final class DefaultRepositoryCache implements RepositoryCache {
 
-    private final Map<Object, Object> cache = new ConcurrentHashMap<>(256);
+    private final ConcurrentHashMap<Object, Object> cache = new ConcurrentHashMap<>(256);
 
     public Object get(RepositorySystemSession session, Object key) {
         return cache.get(key);
@@ -40,4 +40,9 @@ public final class DefaultRepositoryCache implements RepositoryCache {
             cache.remove(key);
         }
     }
+
+    @Override
+    public Object computeIfAbsent(RepositorySystemSession session, Object key, Supplier<Object> supplier) {
+        return cache.computeIfAbsent(key, k -> supplier.get());
+    }
 }
diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositoryCache.java b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositoryCache.java
index 9bf6268f..565048c8 100644
--- a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositoryCache.java
+++ b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositoryCache.java
@@ -18,12 +18,16 @@
  */
 package org.eclipse.aether;
 
+import java.util.function.Supplier;
+
 /**
  * Caches auxiliary data used during repository access like already processed metadata. The data in the cache is meant
  * for exclusive consumption by the repository system and is opaque to the cache implementation. <strong>Note:</strong>
  * Actual cache implementations must be thread-safe.
  *
  * @see RepositorySystemSession#getCache()
+ * @noimplement This interface is not intended to be implemented by clients.
+ * @noextend This interface is not intended to be extended by clients.
  */
 public interface RepositoryCache {
 
@@ -53,4 +57,14 @@ public interface RepositoryCache {
      * @return The requested data or {@code null} if none was present in the cache.
      */
     Object get(RepositorySystemSession session, Object key);
+
+    /**
+     * Retrieve or compute the data associated with the specified key.
+     *
+     * @param key The key for which to retrieve the session data, must not be {@code null}.
+     * @param supplier The supplier will compute the new value, must not be {@code null}.
+     * @return The cache data associated with the key.
+     * @since 2.0.0
+     */
+    Object computeIfAbsent(RepositorySystemSession session, Object key, Supplier<Object> supplier);
 }
diff --git a/pom.xml b/pom.xml
index 178a3152..602423fc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -299,6 +299,7 @@
               <configuration>
                 <parameter>
                   <excludes>
+                    <exclude>org.eclipse.aether.RepositoryCache</exclude>
                     <exclude>org.eclipse.aether.RepositoryListener</exclude>
                     <exclude>org.eclipse.aether.RepositorySystem</exclude>
                     <exclude>org.eclipse.aether.RepositorySystemSession</exclude>