Q:

how to add cache control headers to image stored in database served by spring mvc

I am trying to serve some images using  Spring MVC controller,images are  stored in database
Here is how my controller looks like.
@RequestMapping("/getEmployeeImage/{id}")
public String getEmployeeImage(@PathVariable("id") Integer id, HttpServletResponse response, HttpServletRequest request) throws IOException {
    Employee employee = employeeSercice.getEmployee=(id);

    if (employee.getPhoto() != null) {
        response.setContentType("image/jpg");
        byte buf[] = employee.getPhoto();
        try {
            response.getOutputStream().write(buf);
            BufferedOutputStream output = null;
            output = new BufferedOutputStream(response.getOutputStream());
            response.getOutputStream().flush();
            response.getOutputStream().close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {

    }
    return null;
}

how i enable browser side caching ? i already tried response.setHeader("Cache-Control","max-age=361440"); but not working

A:

For cache control you can use annotation 
@CacheControl(isPublic = true, maxAge = 100, sMaxAge = 100), 

after this render the annotation to HTTP Header with Spring MVC interceptor.  
Another way:
int ageValue=100;
String cacheControl = CacheControlHeader.newBuilder()
      .setCacheType(CacheType.PUBLIC)
      .setMaxAge(ageValue)
      .setsMaxAge(ageValue).build().stringValue();

    response.addHeader("Cache-Control", cacheControl);
}

