Class AbstractRequestCache
- All Implemented Interfaces:
org.apache.maven.api.cache.RequestCache
- Direct Known Subclasses:
DefaultRequestCache
RequestCache interface, providing common caching mechanisms
for executing and caching request results in Maven.
This class implements caching strategies for individual and batch requests, ensuring that results are stored and reused where appropriate to optimize performance.
- Since:
- 4.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract <REQ extends org.apache.maven.api.services.Request<?>, REP extends org.apache.maven.api.services.Result<REQ>>
CachingSupplier<REQ, REP> Abstract method to be implemented by subclasses to handle caching logic.<REQ extends org.apache.maven.api.services.Request<?>, REP extends org.apache.maven.api.services.Result<REQ>>
REPExecutes and optionally caches a single request.<REQ extends org.apache.maven.api.services.Request<?>, REP extends org.apache.maven.api.services.Result<REQ>>
List<REP> Executes and optionally caches a batch of requests.protected static <T extends Throwable>
void
-
Constructor Details
-
AbstractRequestCache
public AbstractRequestCache()
-
-
Method Details
-
request
public <REQ extends org.apache.maven.api.services.Request<?>, REP extends org.apache.maven.api.services.Result<REQ>> REP request(REQ req, Function<REQ, REP> supplier) Executes and optionally caches a single request.The caching behavior is determined by the specific implementation of
doCache(Request, Function). If caching is enabled, the result is retrieved from the cache or computed using the supplier function.- Specified by:
requestin interfaceorg.apache.maven.api.cache.RequestCache- Type Parameters:
REQ- The request typeREP- The response type- Parameters:
req- The request object used as the cache keysupplier- The function that provides the response if not cached- Returns:
- The cached or computed response
-
requests
public <REQ extends org.apache.maven.api.services.Request<?>, REP extends org.apache.maven.api.services.Result<REQ>> List<REP> requests(List<REQ> reqs, Function<List<REQ>, List<REP>> supplier) Executes and optionally caches a batch of requests.This method processes a list of requests, utilizing caching where applicable and executing only the non-cached requests using the provided supplier function.
This implementation uses
CachingSupplier.complete(Object)withwait/notifyAllto coordinate batch results, and aThreadLocalre-entrancy guard to prevent deadlocks when batch resolution triggers nested calls (e.g., parent POM resolution during artifact resolution).Concurrent calls for the same request on different threads: the first thread performs the resolution; the second thread's
CachingSupplier.apply(REQ)blocks (viaObject.wait()) untilcomplete()is called, avoiding duplicate work.Re-entrant calls on the same thread: detected via
RESOLVING_ON_THREAD.CachingSupplier.apply(REQ)skips the wait and invokes the fallback supplier directly so the inner call can complete without waiting for the outer call's batch result.- Specified by:
requestsin interfaceorg.apache.maven.api.cache.RequestCache- Type Parameters:
REQ- The request typeREP- The response type- Parameters:
reqs- List of requests to processsupplier- Function to execute the batch of requests- Returns:
- List of results corresponding to the input requests
- Throws:
org.apache.maven.api.cache.BatchRequestException- if any request in the batch fails
-
doCache
protected abstract <REQ extends org.apache.maven.api.services.Request<?>, REP extends org.apache.maven.api.services.Result<REQ>> CachingSupplier<REQ,REP> doCache(REQ req, Function<REQ, REP> supplier) Abstract method to be implemented by subclasses to handle caching logic.This method is responsible for determining whether a request result should be cached, retrieving it from cache if available, or executing the supplier function if necessary.
- Type Parameters:
REQ- The request typeREP- The response type- Parameters:
req- The request objectsupplier- The function that provides the response- Returns:
- A caching supplier that handles caching logic for the request
-
uncheckedThrow
-