Top Description Fields Constructors Methods
org.springframework.web.reactive.resource

public Class CachingResourceResolver

extends AbstractResourceResolver
Class Inheritance
Imports
java.util.ArrayList, .Arrays, .Collections, .List, java.util.stream.Collectors, reactor.core.publisher.Mono, org.springframework.cache.Cache, .CacheManager, org.springframework.core.io.Resource, org.springframework.lang.Nullable, org.springframework.util.Assert, .StringUtils, org.springframework.web.server.ServerWebExchange

A ResourceResolver that resolves resources from a Cache or otherwise delegates to the resolver chain and caches the result.
Authors
Rossen Stoyanchev, Brian Clozel
Since
5.0

Field Summary

Modifier and TypeField and Description
private final Cache
private final List<String>
public static final String
RESOLVED_RESOURCE_CACHE_KEY_PREFIX

The prefix used for resolved resource cache keys.

public static final String
RESOLVED_URL_PATH_CACHE_KEY_PREFIX

The prefix used for resolved URL path cache keys.

Inherited from org.springframework.web.reactive.resource.AbstractResourceResolver:
logger

Constructor Summary

AccessConstructor and Description
public
public
CachingResourceResolver(CacheManager cacheManager, String cacheName)

Method Summary

Modifier and TypeMethod and Description
protected String
computeKey(ServerWebExchange exchange, String requestPath)

public Cache
getCache()

Return the configured Cache.

private String
public List<String>
getContentCodings()

Return a read-only list with the supported content codings.

protected Mono<Resource>
protected Mono<String>
public void
setContentCodings(List<String>
one or more supported content codings
codings
)

Configure the supported content codings from the "Accept-Encoding" header for which to cache resource variations.

Inherited from org.springframework.web.reactive.resource.AbstractResourceResolver:
resolveResourceresolveUrlPath

Field Detail

cacheback to summary
private final Cache cache
contentCodingsback to summary
private final List<String> contentCodings
RESOLVED_RESOURCE_CACHE_KEY_PREFIXback to summary
public static final String RESOLVED_RESOURCE_CACHE_KEY_PREFIX

The prefix used for resolved resource cache keys.

RESOLVED_URL_PATH_CACHE_KEY_PREFIXback to summary
public static final String RESOLVED_URL_PATH_CACHE_KEY_PREFIX

The prefix used for resolved URL path cache keys.

Constructor Detail

CachingResourceResolverback to summary
public CachingResourceResolver(Cache cache)
CachingResourceResolverback to summary
public CachingResourceResolver(CacheManager cacheManager, String cacheName)

Method Detail

computeKeyback to summary
protected String computeKey(ServerWebExchange exchange, String requestPath)
getCacheback to summary
public Cache getCache()

Return the configured Cache.

getContentCodingKeyback to summary
private String getContentCodingKey(ServerWebExchange exchange)
Annotations
@Nullable
getContentCodingsback to summary
public List<String> getContentCodings()

Return a read-only list with the supported content codings.

Since
5.1
resolveResourceInternalback to summary
protected Mono<Resource> resolveResourceInternal(ServerWebExchange exchange, String requestPath, List<? extends Resource> locations, ResourceResolverChain chain)

Implements abstract org.springframework.web.reactive.resource.AbstractResourceResolver.resolveResourceInternal.

Annotations
@Override
resolveUrlPathInternalback to summary
protected Mono<String> resolveUrlPathInternal(String resourceUrlPath, List<? extends Resource> locations, ResourceResolverChain chain)

Implements abstract org.springframework.web.reactive.resource.AbstractResourceResolver.resolveUrlPathInternal.

Annotations
@Override
setContentCodingsback to summary
public void setContentCodings(List<String> codings)

Configure the supported content codings from the "Accept-Encoding" header for which to cache resource variations.

The codings configured here are generally expected to match those configured on EncodedResourceResolver#setContentCodings(List).

By default this property is set to ["br", "gzip"] based on the value of EncodedResourceResolver#DEFAULT_CODINGS.

Parameters
codings:List<String>

one or more supported content codings

Since
5.1