From 1879648e2537cd19d539d9f63404790bf51b9895 Mon Sep 17 00:00:00 2001 From: grimsi <9295182+grimsi@users.noreply.github.com> Date: Thu, 4 Aug 2022 15:57:40 +0200 Subject: [PATCH] Implemented caching of static images --- .../java/de/grimsi/gameyfin/rest/ImageController.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/de/grimsi/gameyfin/rest/ImageController.java b/backend/src/main/java/de/grimsi/gameyfin/rest/ImageController.java index 5f30154..9d2bd79 100644 --- a/backend/src/main/java/de/grimsi/gameyfin/rest/ImageController.java +++ b/backend/src/main/java/de/grimsi/gameyfin/rest/ImageController.java @@ -3,12 +3,16 @@ package de.grimsi.gameyfin.rest; import de.grimsi.gameyfin.service.DownloadService; import lombok.RequiredArgsConstructor; import org.springframework.core.io.Resource; +import org.springframework.http.CacheControl; import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.concurrent.TimeUnit; + /** * This controller handles functionality for images. */ @@ -20,7 +24,9 @@ public class ImageController { private final DownloadService downloadService; @GetMapping(value = "/{imageId}", produces = MediaType.IMAGE_PNG_VALUE) - public Resource getCoverImageForGame(@PathVariable String imageId) { - return downloadService.downloadImage(imageId); + public ResponseEntity getCoverImageForGame(@PathVariable String imageId) { + return ResponseEntity.ok() + .cacheControl(CacheControl.maxAge(365, TimeUnit.DAYS).cachePublic()) + .body(downloadService.downloadImage(imageId)); } }