API: Reduce cache TTL for album / folder cover images #822 #846

This commit is contained in:
Michael Mayer 2021-01-08 09:09:59 +01:00
parent 92df3aa724
commit 4f8af03b55
2 changed files with 10 additions and 5 deletions

View file

@ -25,6 +25,11 @@ func AddCacheHeader(c *gin.Context, maxAge MaxAge) {
c.Header("Cache-Control", fmt.Sprintf("private, max-age=%s, no-transform", maxAge))
}
// AddCoverCacheHeader adds cover image cache control headers to the response.
func AddCoverCacheHeader(c *gin.Context) {
AddCacheHeader(c, CoverCacheTTL)
}
// AddCacheHeader adds thumbnail cache control headers to the response.
func AddThumbCacheHeader(c *gin.Context) {
c.Header("Cache-Control", fmt.Sprintf("private, max-age=%s, no-transform, immutable", ThumbCacheTTL))

View file

@ -257,7 +257,7 @@ func AlbumThumb(router *gin.RouterGroup) {
// Use original file if thumb size exceeds limit, see https://github.com/photoprism/photoprism/issues/157
if thumbType.ExceedsSizeUncached() && c.Query("download") == "" {
log.Debugf("album-thumbs: using original, size exceeds limit (width %d, height %d)", thumbType.Width, thumbType.Height)
AddThumbCacheHeader(c)
AddCoverCacheHeader(c)
c.File(fileName)
return
}
@ -285,7 +285,7 @@ func AlbumThumb(router *gin.RouterGroup) {
log.Debugf("cached %s [%s]", cacheKey, time.Since(start))
}
AddThumbCacheHeader(c)
AddCoverCacheHeader(c)
if c.Query("download") != "" {
c.FileAttachment(thumbnail, f.ShareBase())
@ -341,7 +341,7 @@ func LabelThumb(router *gin.RouterGroup) {
return
}
AddThumbCacheHeader(c)
AddCoverCacheHeader(c)
if c.Query("download") != "" {
c.FileAttachment(cached.FileName, cached.ShareName)
@ -376,7 +376,7 @@ func LabelThumb(router *gin.RouterGroup) {
if thumbType.ExceedsSizeUncached() {
log.Debugf("label-thumbs: using original, size exceeds limit (width %d, height %d)", thumbType.Width, thumbType.Height)
AddThumbCacheHeader(c)
AddCoverCacheHeader(c)
c.File(fileName)
return
@ -405,7 +405,7 @@ func LabelThumb(router *gin.RouterGroup) {
log.Debugf("cached %s [%s]", cacheKey, time.Since(start))
}
AddThumbCacheHeader(c)
AddCoverCacheHeader(c)
if c.Query("download") != "" {
c.FileAttachment(thumbnail, f.ShareBase())