260803_02_ENH: 브라우저 캐싱 7일로 변경 및 설정 yml로 이동
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -35,3 +35,5 @@ out/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
/logs
|
||||
@@ -3,7 +3,7 @@ package com.kri.shorturl.controller;
|
||||
import com.kri.shorturl.service.QRCodeService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import java.time.Duration;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.CacheControl;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -14,11 +14,19 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/qr")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "QRCode", description = "QR Code API")
|
||||
public class QRCodeController {
|
||||
|
||||
private final QRCodeService qrCodeService;
|
||||
private final Duration cacheMaxAge;
|
||||
|
||||
public QRCodeController(
|
||||
QRCodeService qrCodeService,
|
||||
@Value("${kri.qr.cache-max-age:1d}") Duration cacheMaxAge
|
||||
) {
|
||||
this.qrCodeService = qrCodeService;
|
||||
this.cacheMaxAge = cacheMaxAge;
|
||||
}
|
||||
|
||||
@GetMapping(value = "/{encodedUrl}", produces = MediaType.IMAGE_PNG_VALUE)
|
||||
public ResponseEntity<byte[]> getQrCode(@PathVariable String encodedUrl) {
|
||||
@@ -26,7 +34,7 @@ public class QRCodeController {
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.IMAGE_PNG)
|
||||
.cacheControl(CacheControl.maxAge(Duration.ofDays(1)).cachePublic())
|
||||
.cacheControl(CacheControl.maxAge(cacheMaxAge).cachePublic())
|
||||
.body(png);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,12 @@ kri:
|
||||
|
||||
qr:
|
||||
max-url-bytes: 2048
|
||||
cache-max-age: 7d
|
||||
#cache-max-age: 500ms # 밀리초
|
||||
#cache-max-age: 30s # 초
|
||||
#cache-max-age: 10m # 분
|
||||
#cache-max-age: 12h # 시간
|
||||
#cache-max-age: 1d # 일
|
||||
|
||||
|
||||
web:
|
||||
|
||||
Reference in New Issue
Block a user