repos / pico

pico services mono repo
git clone https://github.com/picosh/pico.git

commit
acf6290
parent
50987d0
author
Eric Bower
date
2026-04-22 09:15:16 -0400 EDT
chore(pgs): configurable max items for lru
3 files changed,  +16, -2
M .env.example
+1, -0
1@@ -102,6 +102,7 @@ PGS_PROTOCOL=http
2 PGS_STORAGE_DIR=.storage
3 PGS_DEBUG=1
4 PGS_CACHE_TTL=600s
5+PGS_CACHE_MAX_ITEMS=0
6 
7 PICO_CADDYFILE=./caddy/Caddyfile.pico
8 PICO_V4=
M pkg/apps/pgs/config.go
+8, -0
 1@@ -4,6 +4,7 @@ import (
 2 	"fmt"
 3 	"log/slog"
 4 	"path/filepath"
 5+	"strconv"
 6 	"time"
 7 
 8 	pgsdb "github.com/picosh/pico/pkg/apps/pgs/db"
 9@@ -13,6 +14,7 @@ import (
10 
11 type PgsConfig struct {
12 	CacheTTL           time.Duration
13+	CacheMaxItems      int
14 	Domain             string
15 	MaxAssetSize       int64
16 	MaxSize            uint64
17@@ -74,12 +76,18 @@ func NewPgsConfig(logger *slog.Logger, dbpool pgsdb.PgsDB, st storage.StorageSer
18 	if err != nil {
19 		cacheTTL = 600 * time.Second
20 	}
21+	cacheMaxItemsStr := shared.GetEnv("PGS_CACHE_MAX_ITEMS", "")
22+	cacheMaxItems := 0
23+	if cacheMaxItemsStr != "" {
24+		cacheMaxItems, _ = strconv.Atoi(cacheMaxItemsStr)
25+	}
26 
27 	sshHost := shared.GetEnv("PGS_SSH_HOST", "0.0.0.0")
28 	sshPort := shared.GetEnv("PGS_SSH_PORT", "2222")
29 
30 	cfg := PgsConfig{
31 		CacheTTL:           cacheTTL,
32+		CacheMaxItems:      cacheMaxItems,
33 		Domain:             domain,
34 		MaxAssetSize:       maxAssetSize,
35 		MaxSize:            maxSize,
M pkg/apps/pgs/web.go
+7, -2
 1@@ -112,7 +112,7 @@ func (p *PromCacheMetrics) AddUpstreamRequest() {
 2 func NewPgsHttpCache(cfg *PgsConfig, upstream http.Handler) *httpcache.HttpCache {
 3 	ttl := cfg.CacheTTL
 4 	metrics := NewPromCacheMetrics(cfg.Logger, prometheus.DefaultRegisterer)
 5-	cache := expirable.NewLRU(0, metrics.EvictCacheItem, ttl)
 6+	cache := expirable.NewLRU(cfg.CacheMaxItems, metrics.EvictCacheItem, ttl)
 7 	httpCache := &httpcache.HttpCache{
 8 		Ttl:      ttl,
 9 		Logger:   cfg.Logger,
10@@ -124,7 +124,12 @@ func NewPgsHttpCache(cfg *PgsConfig, upstream http.Handler) *httpcache.HttpCache
11 		},
12 		CacheMetrics: metrics,
13 	}
14-	httpCache.Logger.Info("httpcache initiated", "ttl", httpCache.Ttl, "storage", "lru")
15+	httpCache.Logger.Info(
16+		"httpcache initiated",
17+		"storageType", "expirable.LRU",
18+		"ttl", ttl,
19+		"maxItems", cfg.CacheMaxItems,
20+	)
21 	return httpCache
22 }
23