Interface ContentCachingService
- All Known Implementing Classes:
JCacheContentCachingService
public interface ContentCachingService
Service that supports caching HTTP responses using keys derived from HTTP
requests.
- Since:
- 1.16
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumEnumeration of supported compression types. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringA HTTP response header for the content cache status.static final StringTheCONTENT_CACHE_HEADERvalue for a cache hit.static final StringTheCONTENT_CACHE_HEADERvalue for a cache miss. -
Method Summary
Modifier and TypeMethodDescriptiondefault voidcacheResponse(String key, jakarta.servlet.http.HttpServletRequest request, int statusCode, org.springframework.http.HttpHeaders headers, InputStream content) Cache a response after completing an intercepted response.voidcacheResponse(String key, jakarta.servlet.http.HttpServletRequest request, int statusCode, org.springframework.http.HttpHeaders headers, InputStream content, ContentCachingService.CompressionType compression) Cache a response after completing an intercepted response.keyForRequest(jakarta.servlet.http.HttpServletRequest request) Get a cache key from a HTTP request.sendCachedResponse(String key, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Send a cached response for a given cache key, if possible.
-
Field Details
-
CONTENT_CACHE_HEADER
A HTTP response header for the content cache status.- Since:
- 1.1
- See Also:
-
CONTENT_CACHE_HEADER_HIT
TheCONTENT_CACHE_HEADERvalue for a cache hit.- Since:
- 1.1
- See Also:
-
CONTENT_CACHE_HEADER_MISS
TheCONTENT_CACHE_HEADERvalue for a cache miss.- Since:
- 1.1
- See Also:
-
-
Method Details
-
keyForRequest
Get a cache key from a HTTP request.- Parameters:
request- the HTTP request to derive a key from- Returns:
- the key, or null if the request should not be cached
-
sendCachedResponse
CachedContent sendCachedResponse(String key, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException Send a cached response for a given cache key, if possible.- Parameters:
key- the cache key, returned previously fromkeyForRequest(HttpServletRequest)request- the active HTTP requestresponse- the active HTTP response to send the cached data to- Returns:
- the cached content if the response was successfully handled, null otherwise (for example a cache miss)
- Throws:
IOException- if any IO error occurs
-
cacheResponse
default void cacheResponse(String key, jakarta.servlet.http.HttpServletRequest request, int statusCode, org.springframework.http.HttpHeaders headers, InputStream content) throws IOException Cache a response after completing an intercepted response.- Parameters:
key- the cache key, returned previously fromkeyForRequest(HttpServletRequest)request- the active HTTP requeststatusCode- the resolved HTTP response status codeheaders- the resolved HTTP response headerscontent- the resolved HTTP response content, or null if nonecompression- ifcontenthas been compressed then the compression type, otherwise null- Throws:
IOException- if any IO error occurs
-
cacheResponse
void cacheResponse(String key, jakarta.servlet.http.HttpServletRequest request, int statusCode, org.springframework.http.HttpHeaders headers, InputStream content, ContentCachingService.CompressionType compression) throws IOException Cache a response after completing an intercepted response.- Parameters:
key- the cache key, returned previously fromkeyForRequest(HttpServletRequest)request- the active HTTP requeststatusCode- the resolved HTTP response status codeheaders- the resolved HTTP response headerscontent- the resolved HTTP response content, or null if nonecompression- ifcontenthas been compressed then the compression type, otherwise null- Throws:
IOException- if any IO error occurs- Since:
- 1.1
-