This facade is attached to the exchange and provides a mechanism for handlers to serve cached content. By default a request to serve cached content is interpreted to mean that the resulting response is cacheable, and so by default this will result in the current response being cached (as long as it meets the criteria for caching).
Calling tryServeResponse can also result in the exchange being ended with a not modified response code, if the response headers indicate that this is justified (e.g. if the If-Modified-Since or If-None-Match headers indicate that the client has a cached copy of the response)
This should be installed early in the handler chain, before any content encoding handlers. This allows it to cache compressed copies of the response, which can significantly reduce CPU load.
Note
This cache has no concept of authentication, it assumes that if the underlying handler indicates that a response is cachable, then the current user has been properly authenticated to access that resource, and that the resource will not change per user.
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| public static final AttachmentKey | |
| private final DirectBufferCache | |
| private final HttpServerExchange | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv boolean | |
| public boolean | |
| public boolean | Returns: true if serving succeeded,If this is true then the resulting response will be considered cachable markCacheable)Attempts to serve the response from a cache. |
| ATTACHMENT_KEY | back to summary |
|---|---|
| public static final AttachmentKey<ResponseCache> ATTACHMENT_KEY | |
| cache | back to summary |
|---|---|
| private final DirectBufferCache cache | |
| exchange | back to summary |
|---|---|
| private final HttpServerExchange exchange | |
| responseCachable | back to summary |
|---|---|
| private boolean responseCachable | |
| ResponseCache | back to summary |
|---|---|
| public ResponseCache(final DirectBufferCache cache, final HttpServerExchange exchange) | |
| isResponseCachable | back to summary |
|---|---|
| pack-priv boolean isResponseCachable() | |
| tryServeResponse | back to summary |
|---|---|
| public boolean tryServeResponse() Attempts to serve the response from a cache. If this fails, then the response will be considered cachable, and may be cached to be served by future handlers. If this returns true then the caller should not modify the exchange any more, as this can result in a handoff to an IO thread
| |
| tryServeResponse | back to summary |
|---|---|
| public boolean tryServeResponse(boolean markCacheable) Attempts to serve the response from a cache. If this fails, and the markCachable parameter is true then the response will be considered cachable, and may be cached to be served by future handlers. If this returns true then the caller should not modify the exchange any more, as this can result in a handoff to an IO thread
| |
| Modifier and Type | Field and Description |
|---|---|
| private final DirectBufferCache. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | onComplete(final HttpServerExchange exchange, final Sender sender)
Implements io.
|
| public void | onException(final HttpServerExchange exchange, final Sender sender, final IOException exception)
Implements io.
|
| entry | back to summary |
|---|---|
| private final DirectBufferCache. | |
| DereferenceCallback | back to summary |
|---|---|
| pack-priv DereferenceCallback(DirectBufferCache. | |
| onComplete | back to summary |
|---|---|
| public void onComplete(final HttpServerExchange exchange, final Sender sender) Implements io.
| |
| onException | back to summary |
|---|---|
| public void onException(final HttpServerExchange exchange, final Sender sender, final IOException exception) Implements io.
| |