Class ResponseCache
- java.lang.Object
-
- io.undertow.server.handlers.cache.ResponseCache
-
public class ResponseCache extends Object
Facade for an underlying buffer cache that contains response information.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.
- Author:
- Stuart Douglas
-
-
Field Summary
Fields Modifier and Type Field Description static AttachmentKey<ResponseCache>
ATTACHMENT_KEY
-
Constructor Summary
Constructors Constructor Description ResponseCache(DirectBufferCache cache, HttpServerExchange exchange)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
tryServeResponse()
Attempts to serve the response from a cache.boolean
tryServeResponse(boolean markCacheable)
Attempts to serve the response from a cache.
-
-
-
Field Detail
-
ATTACHMENT_KEY
public static final AttachmentKey<ResponseCache> ATTACHMENT_KEY
-
-
Constructor Detail
-
ResponseCache
public ResponseCache(DirectBufferCache cache, HttpServerExchange exchange)
-
-
Method Detail
-
tryServeResponse
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
- Returns:
true
if serving succeeded,
-
tryServeResponse
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
- Parameters:
markCacheable
- If this is true then the resulting response will be considered cachable- Returns:
true
if serving succeeded,
-
-