From 31dbdb874655967e9bd1813ca166462e6c3d7e4a Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Fri, 3 Sep 2021 21:05:22 -0700 Subject: [PATCH] Increase cache duration for static files --- utils/utils.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/utils/utils.go b/utils/utils.go index 8cd5448d7..bce2b3660 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -165,23 +165,28 @@ func RenderPageContentMarkdown(raw string) string { // GetCacheDurationSecondsForPath will return the number of seconds to cache an item. func GetCacheDurationSecondsForPath(filePath string) int { - if path.Base(filePath) == "thumbnail.jpg" { + filename := path.Base(filePath) + fileExtension := path.Ext(filePath) + + if filename == "thumbnail.jpg" { // Thumbnails re-generate during live return 20 - } else if path.Ext(filePath) == ".js" || path.Ext(filePath) == ".css" { + } else if fileExtension == ".js" || fileExtension == ".css" { // Cache javascript & CSS - return 60 - } else if path.Ext(filePath) == ".ts" { + return 60 * 10 + } else if fileExtension == ".ts" { // Cache video segments as long as you want. They can't change. // This matters most for local hosting of segments for recordings // and not for live or 3rd party storage. return 31557600 - } else if path.Ext(filePath) == ".m3u8" { + } else if fileExtension == ".m3u8" { return 0 + } else if fileExtension == ".jpg" || fileExtension == ".png" || fileExtension == ".gif" { + return 60 * 60 * 24 } // Default cache length in seconds - return 30 + return 60 * 10 } func IsValidUrl(urlToTest string) bool {