Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-5821

HTTP cache and conditional requests support in RestTemplate

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.0 M3
    • Fix Version/s: 5.x Backlog
    • Component/s: Web:Client
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      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);
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                bclozel Brian Clozel
                Reporter:
                olivergierke Oliver Gierke
                Last updater:
                Juergen Hoeller
              • Votes:
                10 Vote for this issue
                Watchers:
                15 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Days since last comment:
                  3 years, 3 weeks ago