Top Description Inners Fields Constructors Methods
io.undertow.server.handlers.cache

public Class ResponseCache

extends Object
Class Inheritance
Imports
java.io.IOException, java.nio.ByteBuffer, io.undertow.UndertowLogger, io.undertow.io.IoCallback, .Sender, io.undertow.server.HttpServerExchange, io.undertow.util.AttachmentKey, .DateUtils, .ETag, .ETagUtils, .Headers, .HttpString, .StatusCodes

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
public static final AttachmentKey<ResponseCache>
private final DirectBufferCache
private final HttpServerExchange
private boolean

Constructor Summary

AccessConstructor and Description
public
ResponseCache(final DirectBufferCache cache, final HttpServerExchange exchange)

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
public boolean

Returns:

true if serving succeeded,
tryServeResponse
()

Attempts to serve the response from a cache.

public boolean

Returns:

true if serving succeeded,
tryServeResponse
(boolean
If this is true then the resulting response will be considered cachable
markCacheable
)

Attempts to serve the response from a cache.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ATTACHMENT_KEYback to summary
public static final AttachmentKey<ResponseCache> ATTACHMENT_KEY
cacheback to summary
private final DirectBufferCache cache
exchangeback to summary
private final HttpServerExchange exchange
responseCachableback to summary
private boolean responseCachable

Constructor Detail

ResponseCacheback to summary
public ResponseCache(final DirectBufferCache cache, final HttpServerExchange exchange)

Method Detail

isResponseCachableback to summary
pack-priv boolean isResponseCachable()
tryServeResponseback 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

Returns:boolean

true if serving succeeded,

tryServeResponseback 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

Parameters
markCacheable:boolean

If this is true then the resulting response will be considered cachable

Returns:boolean

true if serving succeeded,

io.undertow.server.handlers.cache back to summary

private Class ResponseCache.DereferenceCallback

extends Object
implements IoCallback
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.cache.ResponseCache.DereferenceCallback
All Implemented Interfaces
io.undertow.io.IoCallback

Field Summary

Modifier and TypeField and Description
private final DirectBufferCache.CacheEntry

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
public void
onException(final HttpServerExchange exchange, final Sender sender, final IOException exception)

Implements io.undertow.io.IoCallback.onException.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

entryback to summary
private final DirectBufferCache.CacheEntry entry

Constructor Detail

DereferenceCallbackback to summary
pack-priv DereferenceCallback(DirectBufferCache.CacheEntry entry)

Method Detail

onCompleteback to summary
public void onComplete(final HttpServerExchange exchange, final Sender sender)

Implements io.undertow.io.IoCallback.onComplete.

Annotations
@Override
onExceptionback to summary
public void onException(final HttpServerExchange exchange, final Sender sender, final IOException exception)

Implements io.undertow.io.IoCallback.onException.

Annotations
@Override