使用springboot缓存图片

@ResponseBody
@RequestMapping(value = "/images/{path}", method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE)
@Cacheable("images")
public byte[] image(@PathVariable path) throws IOException {
    InputStream in = servletContext.getResourceAsStream("images/"+path);
    return IOUtils.toByteArray(in);
}

 

https://stackoverflow.com/questions/48742369/how-to-cache-image-files-in-spring-java-application/48744004

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-caching.html

 

可以使用springboot+redis等实现了nginx的一个本地缓存功能

 

posted @ 2021-11-15 14:37  multitude  阅读(487)  评论(0编辑  收藏  举报