Class AbstractRequestCache
- All Implemented Interfaces:
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 Request<?>,
REP extends Result<REQ>>
CachingSupplier<REQ,REP> Abstract method to be implemented by subclasses to handle caching logic.Executes and optionally caches a single request.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 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 interfaceRequestCache
- 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 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 interfaceRequestCache
- 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:
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 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
- Throws:
T extends Throwable
-