Config: Rename HttpCacheTTL to HttpCacheMaxAge #3297

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2023-03-20 20:37:07 +01:00
parent 3dfa6dc4f4
commit f63ac04956
9 changed files with 27 additions and 27 deletions

View file

@ -10,8 +10,8 @@ import (
"github.com/photoprism/photoprism/internal/thumb"
)
// CoverCacheTTL specifies the number of seconds to cache album covers.
var CoverCacheTTL thumb.MaxAge = 3600 // 1 hour
// CoverMaxAge specifies the number of seconds to cache album covers.
var CoverMaxAge thumb.MaxAge = 3600 // 1 hour
type ThumbCache struct {
FileName string
@ -81,14 +81,14 @@ func AddCacheHeader(c *gin.Context, maxAge thumb.MaxAge, public bool) {
// AddCoverCacheHeader adds cover image cache control headers to the response.
func AddCoverCacheHeader(c *gin.Context) {
AddCacheHeader(c, CoverCacheTTL, thumb.CachePublic)
AddCacheHeader(c, CoverMaxAge, thumb.CachePublic)
}
// AddThumbCacheHeader adds thumbnail cache control headers to the response.
func AddThumbCacheHeader(c *gin.Context) {
if thumb.CachePublic {
c.Header("Cache-Control", fmt.Sprintf("public, max-age=%s, no-transform, immutable", thumb.CacheTTL.String()))
c.Header("Cache-Control", fmt.Sprintf("public, max-age=%s, no-transform, immutable", thumb.CacheMaxAge.String()))
} else {
c.Header("Cache-Control", fmt.Sprintf("private, max-age=%s, no-transform, immutable", thumb.CacheTTL.String()))
c.Header("Cache-Control", fmt.Sprintf("private, max-age=%s, no-transform, immutable", thumb.CacheMaxAge.String()))
}
}

View file

@ -60,7 +60,7 @@ func startAction(ctx *cli.Context) error {
{"detach-server", fmt.Sprintf("%t", conf.DetachServer())},
{"http-mode", conf.HttpMode()},
{"http-compression", conf.HttpCompression()},
{"http-cache-ttl", fmt.Sprintf("%d", conf.HttpCacheTTL())},
{"http-cache-maxage", fmt.Sprintf("%d", conf.HttpCacheMaxAge())},
{"http-cache-public", fmt.Sprintf("%t", conf.HttpCachePublic())},
{"http-host", conf.HttpHost()},
{"http-port", fmt.Sprintf("%d", conf.HttpPort())},

View file

@ -165,7 +165,7 @@ func (c *Config) Propagate() {
thumb.SizeUncached = c.ThumbSizeUncached()
thumb.Filter = c.ThumbFilter()
thumb.JpegQuality = c.JpegQuality()
thumb.CacheTTL = c.HttpCacheTTL()
thumb.CacheMaxAge = c.HttpCacheMaxAge()
thumb.CachePublic = c.HttpCachePublic()
// Set geocoding parameters.

View file

@ -83,17 +83,17 @@ func (c *Config) HttpCompression() string {
return strings.ToLower(strings.TrimSpace(c.options.HttpCompression))
}
// HttpCacheTTL returns the HTTP response cache time in seconds.
func (c *Config) HttpCacheTTL() thumb.MaxAge {
if c.options.HttpCacheTTL < 1 || c.options.HttpCacheTTL > 31536000 {
// HttpCacheMaxAge returns the time in seconds until cached content expires.
func (c *Config) HttpCacheMaxAge() thumb.MaxAge {
if c.options.HttpCacheMaxAge < 1 || c.options.HttpCacheMaxAge > 31536000 {
// Default to one month.
return thumb.CacheTTL
return thumb.CacheMaxAge
}
return thumb.MaxAge(c.options.HttpCacheTTL)
return thumb.MaxAge(c.options.HttpCacheMaxAge)
}
// HttpCachePublic checks whether HTTP responses may be cached publicly, e.g. by a CDN.
// HttpCachePublic checks whether static content may be cached by a CDN or caching proxy.
func (c *Config) HttpCachePublic() bool {
if c.options.HttpCachePublic {
return true

View file

@ -52,14 +52,14 @@ func TestConfig_HttpCompression(t *testing.T) {
assert.Equal(t, "", c.HttpCompression())
}
func TestConfig_HttpCacheTTL(t *testing.T) {
func TestConfig_HttpCacheMaxAge(t *testing.T) {
c := NewConfig(CliTestContext())
assert.Equal(t, thumb.MaxAge(2592000), c.HttpCacheTTL())
c.Options().HttpCacheTTL = 23
assert.Equal(t, thumb.MaxAge(23), c.HttpCacheTTL())
c.Options().HttpCacheTTL = 0
assert.Equal(t, thumb.MaxAge(2592000), c.HttpCacheTTL())
assert.Equal(t, thumb.MaxAge(2592000), c.HttpCacheMaxAge())
c.Options().HttpCacheMaxAge = 23
assert.Equal(t, thumb.MaxAge(23), c.HttpCacheMaxAge())
c.Options().HttpCacheMaxAge = 0
assert.Equal(t, thumb.MaxAge(2592000), c.HttpCacheMaxAge())
}
func TestConfig_HttpCachePublic(t *testing.T) {

View file

@ -484,14 +484,14 @@ var Flags = CliFlags{
EnvVar: EnvVar("HTTP_COMPRESSION"),
}}, {
Flag: cli.IntFlag{
Name: "http-cache-ttl",
Value: int(thumb.CacheTTL),
Usage: "number of `SECONDS` that a browser or CDN is allowed to cache HTTP responses",
EnvVar: EnvVar("HTTP_CACHE_TTL"),
Name: "http-cache-maxage",
Value: int(thumb.CacheMaxAge),
Usage: "time in `SECONDS` until cached content expires",
EnvVar: EnvVar("HTTP_CACHE_MAXAGE"),
}}, {
Flag: cli.BoolFlag{
Name: "http-cache-public",
Usage: "allow HTTP responses to be stored in a public cache, e.g. a CDN or caching proxy",
Usage: "allow static content to be cached by a CDN or caching proxy",
EnvVar: EnvVar("HTTP_CACHE_PUBLIC"),
}}, {
Flag: cli.StringFlag{

View file

@ -110,7 +110,7 @@ type Options struct {
TLSKey string `yaml:"TLSKey" json:"TLSKey" flag:"tls-key"`
HttpMode string `yaml:"HttpMode" json:"-" flag:"http-mode"`
HttpCompression string `yaml:"HttpCompression" json:"-" flag:"http-compression"`
HttpCacheTTL int `yaml:"HttpCacheTTL" json:"HttpCacheTTL" flag:"http-cache-ttl"`
HttpCacheMaxAge int `yaml:"HttpCacheMaxAge" json:"HttpCacheMaxAge" flag:"http-cache-maxage"`
HttpCachePublic bool `yaml:"HttpCachePublic" json:"HttpCachePublic" flag:"http-cache-public"`
HttpHost string `yaml:"HttpHost" json:"-" flag:"http-host"`
HttpPort int `yaml:"HttpPort" json:"-" flag:"http-port"`

View file

@ -158,7 +158,7 @@ func (c *Config) Report() (rows [][]string, cols []string) {
{"tls-key", c.TLSKey()},
{"http-mode", c.HttpMode()},
{"http-compression", c.HttpCompression()},
{"http-cache-ttl", fmt.Sprintf("%d", c.HttpCacheTTL())},
{"http-cache-maxage", fmt.Sprintf("%d", c.HttpCacheMaxAge())},
{"http-cache-public", fmt.Sprintf("%t", c.HttpCachePublic())},
{"http-host", c.HttpHost()},
{"http-port", fmt.Sprintf("%d", c.HttpPort())},

View file

@ -11,6 +11,6 @@ func (a MaxAge) String() string {
}
var (
CacheTTL MaxAge = 2592000
CacheMaxAge MaxAge = 2592000
CachePublic = false
)