Package net.targetr.wtm3.cache
Class ResponseCache
java.lang.Object
net.targetr.wtm3.cache.ResponseCache
Quickly builds responses using a resource cache.
- Author:
- Dr Michael Gardiner
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a cache source with optional headers. -
Constructor Summary
ConstructorsConstructorDescriptionResponseCache(ResponseCache.Source... sources) Constructs a ResponseCache with the given resource cache sources. -
Method Summary
Modifier and TypeMethodDescriptionbooleanCheck if a resource is availablebyte[]Gets the byte array content of a resource from the cache sources.getStaticResponse(HttpRequest httpReq, String path) Interrogates the generalized application ResourceCache for a specific network path.getStaticResponse(HttpRequest httpReq, String path, String contentType) Interrogates the generalized application ResourceCache for a specific network path.static StringGuesses the MIME type from a given request path extension.voidInvalidate the cache.
-
Constructor Details
-
ResponseCache
Constructs a ResponseCache with the given resource cache sources.- Parameters:
sources- The ResourceCaches to access for the sources of the response.
-
-
Method Details
-
getStaticResponse
Interrogates the generalized application ResourceCache for a specific network path.- Parameters:
httpReq- the active network requestpath- the designated internal resource path- Returns:
- an HTTP response encoding the discovered resource
- Throws:
IOException- on an underlying cache access block
-
getStaticResponse
public HttpResponse getStaticResponse(HttpRequest httpReq, String path, String contentType) throws HttpErrorResponseException, IOException Interrogates the generalized application ResourceCache for a specific network path.- Parameters:
httpReq- the active network requestpath- the designated internal resource pathcontentType- the forced static content MIME mapping- Returns:
- an HTTP response encoding the discovered resource
- Throws:
HttpErrorResponseException- on a general error accessing the static responseIOException- on a more serious I/O error
-
getBytes
Gets the byte array content of a resource from the cache sources.- Parameters:
path- the path to the resource- Returns:
- the byte array content
- Throws:
IOException- if the resource was not found or an I/O error occurred
-
available
Check if a resource is available- Parameters:
path- the path to the resource- Returns:
- true if the resource is accessible via resource cache sources
-
invalidate
public void invalidate()Invalidate the cache. All items in the cache will be removed. -
getType
Guesses the MIME type from a given request path extension.- Parameters:
path- the resource's network path- Returns:
- the matching predefined string describing its content type
-