public class ResponseCache extends Object
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 | Field and Description |
---|---|
static AttachmentKey<ResponseCache> | ATTACHMENT_KEY |
Constructor and Description |
---|
ResponseCache(DirectBufferCache cache, HttpServerExchange exchange) |
Modifier and Type | Method and Description |
---|---|
boolean | tryServeResponse() Attempts to serve the response from a cache. |
boolean | tryServeResponse(boolean markCacheable) Attempts to serve the response from a cache. |
public static final AttachmentKey<ResponseCache> ATTACHMENT_KEY
public ResponseCache(DirectBufferCache cache, HttpServerExchange exchange)
public boolean tryServeResponse()
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
true
if serving succeeded,public boolean tryServeResponse(boolean markCacheable)
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
markCacheable
- If this is true then the resulting response will be considered cachabletrue
if serving succeeded,Copyright © 2020 JBoss by Red Hat. All rights reserved.