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

public Class CachingResourceResolver

extends AbstractResourceResolver
Class Inheritance
Imports
java.util.ArrayList, .Arrays, .Collections, .List, java.util.stream.Collectors, jakarta.servlet.http.HttpServletRequest, org.springframework.cache.Cache, .CacheManager, org.springframework.core.io.Resource, org.springframework.http.HttpHeaders, org.springframework.lang.Nullable, org.springframework.util.Assert, .StringUtils

A org.springframework.web.servlet.resource.ResourceResolver that resolves resources from a org.springframework.cache.Cache or otherwise delegates to the resolver chain and saves the result in the cache.
Authors
Rossen Stoyanchev, Brian Clozel
Since
4.1

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.servlet.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(HttpServletRequest request, 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 Resource
protected 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.servlet.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(HttpServletRequest request, String requestPath)
getCacheback to summary
public Cache getCache()

Return the configured Cache.

getContentCodingKeyback to summary
private String getContentCodingKey(HttpServletRequest request)
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 Resource resolveResourceInternal(HttpServletRequest request, String requestPath, List<? extends Resource> locations, ResourceResolverChain chain)

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

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

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

Annotations
@Override
@Nullable
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