Class AbstractRequestCache

java.lang.Object
org.apache.maven.impl.cache.AbstractRequestCache
All Implemented Interfaces:
RequestCache
Direct Known Subclasses:
DefaultRequestCache

public abstract class AbstractRequestCache extends Object implements RequestCache
Abstract implementation of the 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 Details

    • AbstractRequestCache

      public AbstractRequestCache()
  • Method Details

    • request

      public <REQ extends Request<?>, REP extends 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:
      request in interface RequestCache
      Type Parameters:
      REQ - The request type
      REP - The response type
      Parameters:
      req - The request object used as the cache key
      supplier - The function that provides the response if not cached
      Returns:
      The cached or computed response
    • requests

      public <REQ extends Request<?>, REP extends 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.

      If any request in the batch fails, a BatchRequestException is thrown, containing details of all failed requests.

      Specified by:
      requests in interface RequestCache
      Type Parameters:
      REQ - The request type
      REP - The response type
      Parameters:
      reqs - List of requests to process
      supplier - Function to execute the batch of requests
      Returns:
      List of results corresponding to the input requests
      Throws:
      BatchRequestException - if any request in the batch fails
    • doCache

      protected abstract <REQ extends Request<?>, REP extends 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 type
      REP - The response type
      Parameters:
      req - The request object
      supplier - The function that provides the response
      Returns:
      A caching supplier that handles caching logic for the request
    • uncheckedThrow

      protected static <T extends Throwable> void uncheckedThrow(Throwable t) throws T
      Throws:
      T extends Throwable