Skip to content
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

[MRESOLVER-450] Enhance RepositoryCache #392

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
*/
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
* for use with short-lived repository system sessions where pruning of cache data is not required.
*/
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);
Expand All @@ -40,4 +40,9 @@ public void put(RepositorySystemSession session, Object key, Object data) {
cache.remove(key);
}
}

@Override
public Object computeIfAbsent(RepositorySystemSession session, Object key, Supplier<Object> supplier) {
return cache.computeIfAbsent(key, k -> supplier.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down