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
-
Constructor Summary
ConstructorsConstructorDescriptionResponseCache(ResourceCache cache) Constructs a ResponseCache with the given resource cache underneath. -
Method Summary
Modifier and TypeMethodDescriptionGet a resource quickly by using cache if possible.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 underneath.- Parameters:
cache- The ResourceCache to use for lookups.
-
-
Method Details
-
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
-
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 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:
IOException- on an underlying cache access block
-
get
Get a resource quickly by using cache if possible.- Parameters:
path- the path to the resource in the cache.contentType- the type to set in the response header.- Returns:
- response containing data from the resource.
- Throws:
IOException- An exception occurred while reading the resource from the cache.
-
invalidate
public void invalidate()Invalidate the cache. All items in the cache will be removed.
-