Class CachingProxy
java.lang.Object
net.targetr.wtm3.net.http.proxy.Proxy
net.targetr.wtm3.net.http.proxy.cache.CachingProxy
A proxy that caches responses from target servers to avoid repeated network requests.
Entries are keyed only by target URL, ignoring request method, body and headers.
Callers must use targets whose responses can be shared on that basis.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCachingProxy(HttpRequest httpReq, String target, long maxAgeMillis, long maxObjectSize, ProxyCache cache) Creates a new caching proxy. -
Method Summary
Modifier and TypeMethodDescriptionReturns a cached body if available; otherwise forwards the request upstream.protected ProxyResponseCreates a ProxyResponse to stream the response back.Methods inherited from class net.targetr.wtm3.net.http.proxy.Proxy
getRequest, getTarget, getTargetConnection
-
Constructor Details
-
CachingProxy
public CachingProxy(HttpRequest httpReq, String target, long maxAgeMillis, long maxObjectSize, ProxyCache cache) Creates a new caching proxy.- Parameters:
httpReq- The incoming HTTP request.target- The target URL to proxy to.maxAgeMillis- The maximum time in milliseconds to keep the response in the cache.maxObjectSize- The maximum size of an object to cache.cache- The cache used to look up and store proxied responses.
-
-
Method Details
-
getResponse
Returns a cached body if available; otherwise forwards the request upstream. Cache hits use status 200 and retain content type and encoding, not all upstream headers.- Overrides:
getResponsein classProxy- Returns:
- Response for proxying data from the target address. Or ErrorResponse.
- Throws:
Exception- An exception occured while connecting to the target or sending request.
-
makeResponse
Description copied from class:ProxyCreates a ProxyResponse to stream the response back.- Overrides:
makeResponsein classProxy- Returns:
- A new ProxyResponse instance.
- Throws:
Exception- If an error occurs creating the response.
-