I am trying to cache ResponseEntity in spring boot but unable to find a proper way to implement the same.
There are few examples where
return ResponseEntity.ok()
.cacheControl(CacheControl.maxAge(20, TimeUnit.SECONDS))
.body(body);
But my problem here is that I am using an external library that returns
ResponseEntity<Resource>
and I wanted to cache that response. so it should be like
ResponseEntity<Resource> getResource() {
ResponseEntity<Resource> resource = getResourceFromExternalFunction();
// wanted to cache this resource
return cachedResource
}
If I apply above technique for my code, it would be like
ResponseEntity<Resource> getResource() {
ResponseEntity<Resource> resource = getResourceFromExternalFunction();
return ResponseEntity.ok()
.cacheControl(CacheControl.maxAge(20, TimeUnit.SECONDS))
.body(resource );
}
it would return
ResourceEntity<ResourceEntity<Resource>>
which is not expected. Can some one help here please