From be076616cc3fda445d511487362901ec3dd458c3 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Thu, 7 Sep 2023 21:57:45 +0200 Subject: [PATCH] Add cache policy to images --- back/src/Kyoo.Core/Views/Helper/CrudThumbsApi.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/back/src/Kyoo.Core/Views/Helper/CrudThumbsApi.cs b/back/src/Kyoo.Core/Views/Helper/CrudThumbsApi.cs index 4674b6ff..697e75cc 100644 --- a/back/src/Kyoo.Core/Views/Helper/CrudThumbsApi.cs +++ b/back/src/Kyoo.Core/Views/Helper/CrudThumbsApi.cs @@ -68,6 +68,14 @@ namespace Kyoo.Core.Api string path = _thumbs.GetImagePath(resource, image, quality ?? ImageQuality.High); if (path == null || !System.IO.File.Exists(path)) return NotFound(); + + if (!identifier.Match(id => false, slug => slug == "random")) + { + // Allow clients to cache the image for 6 month. + Response.Headers.Add("Cache-Control", $"public, max-age={60 * 60 * 24 * 31 * 6}"); + } + else + Response.Headers.Add("Cache-Control", $"public, no-store"); return PhysicalFile(Path.GetFullPath(path), "image/webp", true); }