Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pgs): Configure cache-control, TTL, max body, exclude /check #176

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ PGS_DOMAIN=pgs.dev.pico.sh:3005
PGS_PROTOCOL=http
PGS_STORAGE_DIR=.storage
PGS_DEBUG=1
PGS_CACHE_USER=testuser
PGS_CACHE_PASSWORD=password
PGS_CACHE_TTL=600s

PICO_CADDYFILE=./caddy/Caddyfile.pico
PICO_V4=
Expand Down
16 changes: 12 additions & 4 deletions pgs/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package pgs

import (
"fmt"
"time"

"github.com/picosh/pico/shared"
"github.com/picosh/utils"
)
Expand All @@ -16,8 +19,13 @@ func NewConfigSite() *shared.ConfigSite {
port := utils.GetEnv("PGS_WEB_PORT", "3000")
protocol := utils.GetEnv("PGS_PROTOCOL", "https")
storageDir := utils.GetEnv("PGS_STORAGE_DIR", ".storage")
pgsCacheUser := utils.GetEnv("PGS_CACHE_USER", "")
pgsCachePass := utils.GetEnv("PGS_CACHE_PASSWORD", "")
cacheTTL, err := time.ParseDuration(utils.GetEnv("PGS_CACHE_TTL", ""))
if err != nil {
cacheTTL = 600 * time.Second
}
cacheControl := utils.GetEnv(
"PGS_CACHE_CONTROL",
fmt.Sprintf("max-age=%d", int(cacheTTL.Seconds())))
minioURL := utils.GetEnv("MINIO_URL", "")
minioUser := utils.GetEnv("MINIO_ROOT_USER", "")
minioPass := utils.GetEnv("MINIO_ROOT_PASSWORD", "")
Expand All @@ -29,8 +37,8 @@ func NewConfigSite() *shared.ConfigSite {
Protocol: protocol,
DbURL: dbURL,
StorageDir: storageDir,
CacheUser: pgsCacheUser,
CachePassword: pgsCachePass,
CacheTTL: cacheTTL,
CacheControl: cacheControl,
MinioURL: minioURL,
MinioUser: minioUser,
MinioPass: minioPass,
Expand Down
11 changes: 8 additions & 3 deletions pgs/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,26 @@ func StartApiServer() {
logger.Error("could not connect to object storage", "err", err.Error())
return
}

stale := configurationtypes.Duration{Duration: 1000 * time.Second}
ttl := configurationtypes.Duration{Duration: cfg.CacheTTL}
stale := configurationtypes.Duration{Duration: cfg.CacheTTL * 2}
c := &middleware.BaseConfiguration{
API: configurationtypes.API{
Prometheus: configurationtypes.APIEndpoint{
Enable: true,
},
},
DefaultCache: &configurationtypes.DefaultCache{
TTL: configurationtypes.Duration{Duration: 300 * time.Second},
TTL: ttl,
Stale: stale,
Otter: configurationtypes.CacheProvider{
Uuid: fmt.Sprintf("OTTER-%s", stale),
Configuration: map[string]interface{}{},
},
Regex: configurationtypes.Regex{
Exclude: "/check",
},
MaxBodyBytes: uint64(cfg.MaxAssetSize),
DefaultCacheControl: cfg.CacheControl,
},
LogLevel: "debug",
}
Expand Down
4 changes: 2 additions & 2 deletions shared/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type ConfigSite struct {
Protocol string
DbURL string
StorageDir string
CacheUser string
CachePassword string
CacheTTL time.Duration
CacheControl string
MinioURL string
MinioUser string
MinioPass string
Expand Down
Loading