From 2c4272d5f1c789a855d0380ff2eeaa7052d553cf Mon Sep 17 00:00:00 2001 From: Julio Verne <55258516+julio-ufpb@users.noreply.github.com> Date: Thu, 29 Aug 2024 18:44:57 -0300 Subject: [PATCH] change: use cache in minio image endpoint --- .../me/universi/image/controller/ImageController.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/universi/image/controller/ImageController.java b/src/main/java/me/universi/image/controller/ImageController.java index 554d6366..13a009e8 100644 --- a/src/main/java/me/universi/image/controller/ImageController.java +++ b/src/main/java/me/universi/image/controller/ImageController.java @@ -53,6 +53,8 @@ public Response upload_of_image(@RequestParam("imagem") MultipartFile image) { // get image from minIO @GetMapping(value = "/img/minio/{imageId}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) + @ResponseBody + @Cacheable("img") public ResponseEntity getImageFromMinio(@PathVariable("imageId") String imageId) { try { //Recupera a imagem do MinIO @@ -70,9 +72,12 @@ public ResponseEntity getImageFromMinio(@PathVariable("imageId") String stream.close(); //Retorna os bytes da imagem com um status HTTP 200 OK - return ResponseEntity.ok() - .contentType(MediaType.APPLICATION_OCTET_STREAM) - .body(imageBytes); + return ResponseEntity + .ok() + .contentLength(imageBytes.length) + .contentType(MediaType.APPLICATION_OCTET_STREAM) + .cacheControl(CacheControl.maxAge(365, TimeUnit.DAYS)) + .body(imageBytes); } catch (Exception e) { //Se ocorrer um erro ao recuperar a imagem, retorna um status HTTP 404 Not Found return ResponseEntity.notFound().build();