Closed
Description
Oliver Drotbohm opened SPR-5821 and commented
The main goal is to create a CachingClientHttpRequestInterceptor
which provides the following:
- Cache the received HTTP responses for further use, if those are marked as cacheable
- Cache those response in a
org.springframework.cache.Cache
- if the Cache contains a valid response but its content is stale, then the Interceptor can issue conditional requests to revalidate the cached content
- by default, a sane configuration should be provided and the Cache should be backed by a
ConcurrentCacheMap
This could be used like this:
RestTemplate restTemplate = new RestTemplate();
restTemplate.setInterceptors(Collections.singletonList(new CachingClientHttpRequestInterceptor()));
// this response is cacheable and has appropriate headers
ResponseEntity<Book> response = restTemplate.getForEntity("http://example.org/resource", Book.class);
// it is now cached
String etag = response.getHeaders().getEtag();
// if the response is still fresh, then no network call should happen and the response should be reused
Book book = restTemplate.getForObject("http://example.org/resource", Book.class);
Affects: 3.0 M3
Attachments:
- CachingHttpRequestFactory.java (8.51 kB)
- ETagCachingRestTemplate.java (7.98 kB)
Issue Links:
- Introduce interceptors for RestTemplate [SPR-7494] #12152 Introduce interceptors for RestTemplate ("depends on")
- Server-side HTTP caching improvements [SPR-11792] #16413 Server-side HTTP caching improvements
- Provide high-level cache API in Spring container [SPR-7308] #11967 Provide high-level cache API in Spring container
10 votes, 15 watchers