cmd/packserver: better default behaviour for --expiry404
Now inherits from --expiry, but with a maximum of 60s. Intended to allow for short negative caching, without causing issues with newly-created assets.
This commit is contained in:
parent
7d96b5bdcb
commit
8dd8ebacc1
1 changed files with 10 additions and 4 deletions
|
|
@ -56,7 +56,7 @@ func main() {
|
||||||
rootCmd.Flags().Duration("expiry", 0,
|
rootCmd.Flags().Duration("expiry", 0,
|
||||||
"Tell client how long it can cache data for; 0 means no caching")
|
"Tell client how long it can cache data for; 0 means no caching")
|
||||||
rootCmd.Flags().Duration("expiry404", 0,
|
rootCmd.Flags().Duration("expiry404", 0,
|
||||||
"Tell client how long it can cache 404 responses for; 0 means no caching")
|
"Tell client how long it can cache 404 responses for; 0 means default (inherit from --expiry, max. 60s); -1 means no caching")
|
||||||
rootCmd.Flags().String("fallback-404", "",
|
rootCmd.Flags().String("fallback-404", "",
|
||||||
"Name of file to return if response would be 404 (spa.html or similar)")
|
"Name of file to return if response would be 404 (spa.html or similar)")
|
||||||
rootCmd.Flags().String("frames", "sameorigin",
|
rootCmd.Flags().String("frames", "sameorigin",
|
||||||
|
|
@ -145,12 +145,18 @@ func run(c *cobra.Command, args []string) error {
|
||||||
if expiry > 0 {
|
if expiry > 0 {
|
||||||
cacheControl200 = fmt.Sprintf("public, max-age=%d", expiry/1e9)
|
cacheControl200 = fmt.Sprintf("public, max-age=%d", expiry/1e9)
|
||||||
}
|
}
|
||||||
expiry, err = c.Flags().GetDuration("expiry404")
|
|
||||||
|
expiry404, err := c.Flags().GetDuration("expiry404")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if expiry > 0 {
|
switch {
|
||||||
cacheControl404 = fmt.Sprintf("public, max-age=%d", expiry/1e9)
|
case expiry404 == 0 && expiry == 0:
|
||||||
|
case expiry404 == 0 && expiry > 0:
|
||||||
|
expiry404 = min(60*time.Second, expiry)
|
||||||
|
fallthrough
|
||||||
|
case expiry404 > 0:
|
||||||
|
cacheControl404 = fmt.Sprintf("public, max-age=%d", expiry404/1e9)
|
||||||
}
|
}
|
||||||
|
|
||||||
// optional index file
|
// optional index file
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue