Commit acf6290
Eric Bower
·
2026-04-22 09:15:16 -0400 EDT
parent 50987d0
chore(pgs): configurable max items for lru
3 files changed,
+16,
-2
+1,
-0
| ... | ... | @@ -102,6 +102,7 @@ PGS_PROTOCOL=http | |
| 102 | 102 | PGS_STORAGE_DIR=.storage | |
| 103 | 103 | PGS_DEBUG=1 | |
| 104 | 104 | PGS_CACHE_TTL=600s | |
| 105 | + | PGS_CACHE_MAX_ITEMS=0 | |
| 105 | 106 | ||
| 106 | 107 | PICO_CADDYFILE=./caddy/Caddyfile.pico | |
| 107 | 108 | PICO_V4= |
+8,
-0
| ... | ... | @@ -4,6 +4,7 @@ import ( | |
| 4 | 4 | "fmt" | |
| 5 | 5 | "log/slog" | |
| 6 | 6 | "path/filepath" | |
| 7 | + | "strconv" | |
| 7 | 8 | "time" | |
| 8 | 9 | ||
| 9 | 10 | pgsdb "github.com/picosh/pico/pkg/apps/pgs/db" |
| ... | ... | @@ -13,6 +14,7 @@ import ( | |
| 13 | 14 | ||
| 14 | 15 | type PgsConfig struct { | |
| 15 | 16 | CacheTTL time.Duration | |
| 17 | + | CacheMaxItems int | |
| 16 | 18 | Domain string | |
| 17 | 19 | MaxAssetSize int64 | |
| 18 | 20 | MaxSize uint64 |
| ... | ... | @@ -74,12 +76,18 @@ func NewPgsConfig(logger *slog.Logger, dbpool pgsdb.PgsDB, st storage.StorageSer | |
| 74 | 76 | if err != nil { | |
| 75 | 77 | cacheTTL = 600 * time.Second | |
| 76 | 78 | } | |
| 79 | + | cacheMaxItemsStr := shared.GetEnv("PGS_CACHE_MAX_ITEMS", "") | |
| 80 | + | cacheMaxItems := 0 | |
| 81 | + | if cacheMaxItemsStr != "" { | |
| 82 | + | cacheMaxItems, _ = strconv.Atoi(cacheMaxItemsStr) | |
| 83 | + | } | |
| 77 | 84 | ||
| 78 | 85 | sshHost := shared.GetEnv("PGS_SSH_HOST", "0.0.0.0") | |
| 79 | 86 | sshPort := shared.GetEnv("PGS_SSH_PORT", "2222") | |
| 80 | 87 | ||
| 81 | 88 | cfg := PgsConfig{ | |
| 82 | 89 | CacheTTL: cacheTTL, | |
| 90 | + | CacheMaxItems: cacheMaxItems, | |
| 83 | 91 | Domain: domain, | |
| 84 | 92 | MaxAssetSize: maxAssetSize, | |
| 85 | 93 | MaxSize: maxSize, |
+7,
-2
| ... | ... | @@ -112,7 +112,7 @@ func (p *PromCacheMetrics) AddUpstreamRequest() { | |
| 112 | 112 | func NewPgsHttpCache(cfg *PgsConfig, upstream http.Handler) *httpcache.HttpCache { | |
| 113 | 113 | ttl := cfg.CacheTTL | |
| 114 | 114 | metrics := NewPromCacheMetrics(cfg.Logger, prometheus.DefaultRegisterer) | |
| 115 | - | cache := expirable.NewLRU(0, metrics.EvictCacheItem, ttl) | |
| 115 | + | cache := expirable.NewLRU(cfg.CacheMaxItems, metrics.EvictCacheItem, ttl) | |
| 116 | 116 | httpCache := &httpcache.HttpCache{ | |
| 117 | 117 | Ttl: ttl, | |
| 118 | 118 | Logger: cfg.Logger, |
| ... | ... | @@ -124,7 +124,12 @@ func NewPgsHttpCache(cfg *PgsConfig, upstream http.Handler) *httpcache.HttpCache | |
| 124 | 124 | }, | |
| 125 | 125 | CacheMetrics: metrics, | |
| 126 | 126 | } | |
| 127 | - | httpCache.Logger.Info("httpcache initiated", "ttl", httpCache.Ttl, "storage", "lru") | |
| 127 | + | httpCache.Logger.Info( | |
| 128 | + | "httpcache initiated", | |
| 129 | + | "storageType", "expirable.LRU", | |
| 130 | + | "ttl", ttl, | |
| 131 | + | "maxItems", cfg.CacheMaxItems, | |
| 132 | + | ) | |
| 128 | 133 | return httpCache | |
| 129 | 134 | } | |
| 130 | 135 |