membersound membersound - 1 year ago 137
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download