membersound membersound - 6 months ago 33
HTTP Question

How to add cache-control to a @RestController servlet path?

I have a

to offer images resources via

@RequestMapping(value = "/thumbnails", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> getThumbnail(int id) {
return service.find(id);

Resulting http headers:
Cache-control: "max-age=0"

Question: how can I control the cache header just for that method?


I ended as follows, which worked:

ResponseEntity.ok().lastModified(file.lastModified()).header("max-age", "86400");

I don't now why the approach with CacheControl class does not work.