Skip to content

HTTP cache and conditional requests support in RestTemplate [SPR-5821] #10491

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Issue Links:

10 votes, 15 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions