0

Increase cache duration for static files

This commit is contained in:
Gabe Kangas 2021-09-03 21:05:22 -07:00
parent ae1c2d89f0
commit 31dbdb8746

View File

@ -165,23 +165,28 @@ func RenderPageContentMarkdown(raw string) string {
// GetCacheDurationSecondsForPath will return the number of seconds to cache an item. // GetCacheDurationSecondsForPath will return the number of seconds to cache an item.
func GetCacheDurationSecondsForPath(filePath string) int { 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 // Thumbnails re-generate during live
return 20 return 20
} else if path.Ext(filePath) == ".js" || path.Ext(filePath) == ".css" { } else if fileExtension == ".js" || fileExtension == ".css" {
// Cache javascript & CSS // Cache javascript & CSS
return 60 return 60 * 10
} else if path.Ext(filePath) == ".ts" { } else if fileExtension == ".ts" {
// Cache video segments as long as you want. They can't change. // Cache video segments as long as you want. They can't change.
// This matters most for local hosting of segments for recordings // This matters most for local hosting of segments for recordings
// and not for live or 3rd party storage. // and not for live or 3rd party storage.
return 31557600 return 31557600
} else if path.Ext(filePath) == ".m3u8" { } else if fileExtension == ".m3u8" {
return 0 return 0
} else if fileExtension == ".jpg" || fileExtension == ".png" || fileExtension == ".gif" {
return 60 * 60 * 24
} }
// Default cache length in seconds // Default cache length in seconds
return 30 return 60 * 10
} }
func IsValidUrl(urlToTest string) bool { func IsValidUrl(urlToTest string) bool {