Class JCacheContentCachingService
java.lang.Object
net.solarnetwork.central.web.support.JCacheContentCachingService
- All Implemented Interfaces:
EventListener,javax.cache.event.CacheEntryCreatedListener<String,,CachedContent> javax.cache.event.CacheEntryExpiredListener<String,,CachedContent> javax.cache.event.CacheEntryListener<String,,CachedContent> javax.cache.event.CacheEntryRemovedListener<String,,CachedContent> javax.cache.event.CacheEntryUpdatedListener<String,,CachedContent> CacheUtils.CacheEvictionListener<String,,CachedContent> ContentCachingService,net.solarnetwork.service.PingTest
public class JCacheContentCachingService
extends Object
implements ContentCachingService, net.solarnetwork.service.PingTest, javax.cache.event.CacheEntryCreatedListener<String,CachedContent>, javax.cache.event.CacheEntryExpiredListener<String,CachedContent>, javax.cache.event.CacheEntryUpdatedListener<String,CachedContent>, javax.cache.event.CacheEntryRemovedListener<String,CachedContent>, CacheUtils.CacheEvictionListener<String,CachedContent>
Caching service backed by a
Cache.-
Nested Class Summary
Nested classes/interfaces inherited from interface net.solarnetwork.central.web.support.ContentCachingService
ContentCachingService.CompressionTypeNested classes/interfaces inherited from interface net.solarnetwork.service.PingTest
net.solarnetwork.service.PingTest.Result -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default value for thestatLogAccessCountproperty.Fields inherited from interface net.solarnetwork.central.web.support.ContentCachingService
CONTENT_CACHE_HEADER, CONTENT_CACHE_HEADER_HIT, CONTENT_CACHE_HEADER_MISS -
Constructor Summary
ConstructorsConstructorDescriptionJCacheContentCachingService(javax.cache.Cache<String, CachedContent> cache) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidcacheResponse(String key, jakarta.servlet.http.HttpServletRequest request, int statusCode, org.springframework.http.HttpHeaders headers, InputStream content, ContentCachingService.CompressionType compressionType) Cache a response after completing an intercepted response.List<org.springframework.http.MediaType> getAccept(jakarta.servlet.http.HttpServletRequest request) getCacheContentMetadata(String key, jakarta.servlet.http.HttpServletRequest request, int statusCode, org.springframework.http.HttpHeaders headers) Get metadata for the cache content.longkeyForRequest(jakarta.servlet.http.HttpServletRequest request) Get a cache key for a given request.voidonCacheEviction(String key, CachedContent value) Receive a cache eviction notification.voidonCreated(Iterable<javax.cache.event.CacheEntryEvent<? extends String, ? extends CachedContent>> events) voidonExpired(Iterable<javax.cache.event.CacheEntryEvent<? extends String, ? extends CachedContent>> events) voidonRemoved(Iterable<javax.cache.event.CacheEntryEvent<? extends String, ? extends CachedContent>> events) voidonUpdated(Iterable<javax.cache.event.CacheEntryEvent<? extends String, ? extends CachedContent>> events) net.solarnetwork.service.PingTest.ResultsendCachedResponse(String key, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Send a cached response for a given cache key, if possible.voidsetCompressibleMediaTypes(Set<org.springframework.http.MediaType> compressibleMediaTypes) Configure a set of compressible media types.voidsetCompressMinimumLength(int compressMinimumLength) A minimum size content must be to qualify for storing compressed.voidsetStatLogAccessCount(int statLogAccessCount) Set the statistic log update count.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.solarnetwork.central.web.support.ContentCachingService
cacheResponse
-
Field Details
-
DEFAULT_STAT_LOG_ACCESS_COUNT
public static final int DEFAULT_STAT_LOG_ACCESS_COUNTThe default value for thestatLogAccessCountproperty.- See Also:
-
-
Constructor Details
-
JCacheContentCachingService
Constructor.- Parameters:
cache- the cache to use- Throws:
IllegalArgumentException- if any argument is null
-
-
Method Details
-
getPingTestId
- Specified by:
getPingTestIdin interfacenet.solarnetwork.service.PingTest
-
getPingTestName
- Specified by:
getPingTestNamein interfacenet.solarnetwork.service.PingTest
-
getPingTestMaximumExecutionMilliseconds
public long getPingTestMaximumExecutionMilliseconds()- Specified by:
getPingTestMaximumExecutionMillisecondsin interfacenet.solarnetwork.service.PingTest
-
performPingTest
- Specified by:
performPingTestin interfacenet.solarnetwork.service.PingTest- Throws:
Exception
-
onExpired
public void onExpired(Iterable<javax.cache.event.CacheEntryEvent<? extends String, ? extends CachedContent>> events) throws javax.cache.event.CacheEntryListenerException- Specified by:
onExpiredin interfacejavax.cache.event.CacheEntryExpiredListener<String,CachedContent> - Throws:
javax.cache.event.CacheEntryListenerException
-
onCreated
public void onCreated(Iterable<javax.cache.event.CacheEntryEvent<? extends String, ? extends CachedContent>> events) throws javax.cache.event.CacheEntryListenerException- Specified by:
onCreatedin interfacejavax.cache.event.CacheEntryCreatedListener<String,CachedContent> - Throws:
javax.cache.event.CacheEntryListenerException
-
onUpdated
public void onUpdated(Iterable<javax.cache.event.CacheEntryEvent<? extends String, ? extends CachedContent>> events) throws javax.cache.event.CacheEntryListenerException- Specified by:
onUpdatedin interfacejavax.cache.event.CacheEntryUpdatedListener<String,CachedContent> - Throws:
javax.cache.event.CacheEntryListenerException
-
onRemoved
public void onRemoved(Iterable<javax.cache.event.CacheEntryEvent<? extends String, ? extends CachedContent>> events) throws javax.cache.event.CacheEntryListenerException- Specified by:
onRemovedin interfacejavax.cache.event.CacheEntryRemovedListener<String,CachedContent> - Throws:
javax.cache.event.CacheEntryListenerException
-
onCacheEviction
Description copied from interface:CacheUtils.CacheEvictionListenerReceive a cache eviction notification.- Specified by:
onCacheEvictionin interfaceCacheUtils.CacheEvictionListener<String,CachedContent> - Parameters:
key- the evicted keyvalue- the evicted value
-
getAccept
public List<org.springframework.http.MediaType> getAccept(jakarta.servlet.http.HttpServletRequest request) -
keyForRequest
Get a cache key for a given request.This implementation uses the following components to generate the cache key:
- SolarNetwork authorization user, from the Authorization HTTP header)
- request method (via
HttpServletRequest.getMethod()) - request URI (via
HttpServletRequest.getRequestURI()) - request query parameters
- Accept header value
- Specified by:
keyForRequestin interfaceContentCachingService- Parameters:
request- the HTTP request to derive a key from- Returns:
- the key, or null if the request should not be cached
-
sendCachedResponse
public CachedContent sendCachedResponse(String key, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException Description copied from interface:ContentCachingServiceSend a cached response for a given cache key, if possible.- Specified by:
sendCachedResponsein interfaceContentCachingService- Parameters:
key- the cache key, returned previously fromContentCachingService.keyForRequest(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
public void cacheResponse(String key, jakarta.servlet.http.HttpServletRequest request, int statusCode, org.springframework.http.HttpHeaders headers, InputStream content, ContentCachingService.CompressionType compressionType) throws IOException Description copied from interface:ContentCachingServiceCache a response after completing an intercepted response.- Specified by:
cacheResponsein interfaceContentCachingService- Parameters:
key- the cache key, returned previously fromContentCachingService.keyForRequest(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 nonecompressionType- ifcontenthas been compressed then the compression type, otherwise null- Throws:
IOException- if any IO error occurs
-
getCacheContentMetadata
protected Map<String,?> getCacheContentMetadata(String key, jakarta.servlet.http.HttpServletRequest request, int statusCode, org.springframework.http.HttpHeaders headers) Get metadata for the cache content.This method returns null, so extending classes can override. Note that the returned object must implement
Serializable, along with all values in the map.- Parameters:
key- the cache keyrequest- the active requeststatusCode- the HTTP status codeheaders- the HTTP headers- Returns:
- the metadata, or null if none
-
setCompressibleMediaTypes
public void setCompressibleMediaTypes(Set<org.springframework.http.MediaType> compressibleMediaTypes) Configure a set of compressible media types.- Parameters:
compressibleMediaTypes- compressible media types
-
setCompressMinimumLength
public void setCompressMinimumLength(int compressMinimumLength) A minimum size content must be to qualify for storing compressed.- Parameters:
compressMinimumLength- the minimum length, in bytes
-
setStatLogAccessCount
public void setStatLogAccessCount(int statLogAccessCount) Set the statistic log update count.Setting this to something greater than 0 will cause INFO level statistic log entries to be emitted every
statLogAccessCounttimes a cachable request has been processed.- Parameters:
statLogAccessCount- the access count the access count; defaults toDEFAULT_STAT_LOG_ACCESS_COUNT
-