- commit
- 6886a8e
- parent
- dfbc740
- author
- Mac Chaffee
- date
- 2024-12-17 15:12:45 +0000 UTC
feat(pgs): Configure cache-control, TTL, max body, exclude /check (#176)
4 files changed,
+23,
-11
+1,
-2
1@@ -118,8 +118,7 @@ PGS_DOMAIN=pgs.dev.pico.sh:3005
2 PGS_PROTOCOL=http
3 PGS_STORAGE_DIR=.storage
4 PGS_DEBUG=1
5-PGS_CACHE_USER=testuser
6-PGS_CACHE_PASSWORD=password
7+PGS_CACHE_TTL=600s
8
9 PICO_CADDYFILE=./caddy/Caddyfile.pico
10 PICO_V4=
+12,
-4
1@@ -1,6 +1,9 @@
2 package pgs
3
4 import (
5+ "fmt"
6+ "time"
7+
8 "github.com/picosh/pico/shared"
9 "github.com/picosh/utils"
10 )
11@@ -16,8 +19,13 @@ func NewConfigSite() *shared.ConfigSite {
12 port := utils.GetEnv("PGS_WEB_PORT", "3000")
13 protocol := utils.GetEnv("PGS_PROTOCOL", "https")
14 storageDir := utils.GetEnv("PGS_STORAGE_DIR", ".storage")
15- pgsCacheUser := utils.GetEnv("PGS_CACHE_USER", "")
16- pgsCachePass := utils.GetEnv("PGS_CACHE_PASSWORD", "")
17+ cacheTTL, err := time.ParseDuration(utils.GetEnv("PGS_CACHE_TTL", ""))
18+ if err != nil {
19+ cacheTTL = 600 * time.Second
20+ }
21+ cacheControl := utils.GetEnv(
22+ "PGS_CACHE_CONTROL",
23+ fmt.Sprintf("max-age=%d", int(cacheTTL.Seconds())))
24 minioURL := utils.GetEnv("MINIO_URL", "")
25 minioUser := utils.GetEnv("MINIO_ROOT_USER", "")
26 minioPass := utils.GetEnv("MINIO_ROOT_PASSWORD", "")
27@@ -29,8 +37,8 @@ func NewConfigSite() *shared.ConfigSite {
28 Protocol: protocol,
29 DbURL: dbURL,
30 StorageDir: storageDir,
31- CacheUser: pgsCacheUser,
32- CachePassword: pgsCachePass,
33+ CacheTTL: cacheTTL,
34+ CacheControl: cacheControl,
35 MinioURL: minioURL,
36 MinioUser: minioUser,
37 MinioPass: minioPass,
+8,
-3
1@@ -61,8 +61,8 @@ func StartApiServer() {
2 logger.Error("could not connect to object storage", "err", err.Error())
3 return
4 }
5-
6- stale := configurationtypes.Duration{Duration: 1000 * time.Second}
7+ ttl := configurationtypes.Duration{Duration: cfg.CacheTTL}
8+ stale := configurationtypes.Duration{Duration: cfg.CacheTTL * 2}
9 c := &middleware.BaseConfiguration{
10 API: configurationtypes.API{
11 Prometheus: configurationtypes.APIEndpoint{
12@@ -70,12 +70,17 @@ func StartApiServer() {
13 },
14 },
15 DefaultCache: &configurationtypes.DefaultCache{
16- TTL: configurationtypes.Duration{Duration: 300 * time.Second},
17+ TTL: ttl,
18 Stale: stale,
19 Otter: configurationtypes.CacheProvider{
20 Uuid: fmt.Sprintf("OTTER-%s", stale),
21 Configuration: map[string]interface{}{},
22 },
23+ Regex: configurationtypes.Regex{
24+ Exclude: "/check",
25+ },
26+ MaxBodyBytes: uint64(cfg.MaxAssetSize),
27+ DefaultCacheControl: cfg.CacheControl,
28 },
29 LogLevel: "debug",
30 }
1@@ -38,8 +38,8 @@ type ConfigSite struct {
2 Protocol string
3 DbURL string
4 StorageDir string
5- CacheUser string
6- CachePassword string
7+ CacheTTL time.Duration
8+ CacheControl string
9 MinioURL string
10 MinioUser string
11 MinioPass string