pico
created pr with
59.1
added 59.2
1: 2cf56f0 ! 1: 26daea4 feat(pgs): lru cache for object info and special files
2: caace51 ! 2: b004b64 chore(pgs): use http cache clear event to rm lru cache for special files
added 59.3
1: 26daea4 = 1: 26daea4 feat(pgs): lru cache for object info and special files
2: b004b64 = 2: b004b64 chore(pgs): use http cache clear event to rm lru cache for special files
-: ------- > 3: 59f5618 refactor(pgs): store lru cache on web router
added 59.4
1: 26daea4 = 1: 26daea4 feat(pgs): lru cache for object info and special files
2: b004b64 = 2: b004b64 chore(pgs): use http cache clear event to rm lru cache for special files
3: 59f5618 = 3: 59f5618 refactor(pgs): store lru cache on web router
-: ------- > 4: ee12290 refactor(pgs): update minio lru and remove object info cache
cmds
checkout latest patchset:
ssh pr.pico.sh print 59 | git am -3checkout any patchset in a patch request:
ssh pr.pico.sh print 59.[rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 59
Patchset
59.1
chore(pgs): use http cache clear event to rm lru cache for special files
Eric Bower
2025-04-06T03:01:01ZSemantic diff summary
1 added,
4 modified,
1 signature changed,
0 removed
across 3 analyzed files
+12
-2
pkg/apps/pgs/web.go
#
| ... | ... | @@ -260,7 +260,7 @@ func (web *WebRouter) checkHandler(w http.ResponseWriter, r *http.Request) { | |
| 260 | 260 | w.WriteHeader(http.StatusNotFound) | |
| 261 | 261 | } | |
| 262 | 262 | ||
| 263 | - | func (web *WebRouter) cacheMgmt(ctx context.Context, httpCache *middleware.SouinBaseHandler) { | |
| 263 | + | func (web *WebRouter) cacheMgmt(ctx context.Context, httpCache *middleware.SouinBaseHandler, notify chan string) { | |
| 264 | 264 | storer := httpCache.Storers[0] | |
| 265 | 265 | drain := createSubCacheDrain(ctx, web.Cfg.Logger) | |
| 266 | 266 |
| ... | ... | @@ -270,6 +270,7 @@ func (web *WebRouter) cacheMgmt(ctx context.Context, httpCache *middleware.Souin | |
| 270 | 270 | for scanner.Scan() { | |
| 271 | 271 | surrogateKey := strings.TrimSpace(scanner.Text()) | |
| 272 | 272 | web.Cfg.Logger.Info("received cache-drain item", "surrogateKey", surrogateKey) | |
| 273 | + | notify <- surrogateKey | |
| 273 | 274 | ||
| 274 | 275 | if surrogateKey == "*" { | |
| 275 | 276 | storer.DeleteMany(".+") |
| ... | ... | @@ -509,6 +510,15 @@ func (web *WebRouter) ServeAsset(fname string, opts *storage.ImgProcessOpts, fro | |
| 509 | 510 | } | |
| 510 | 511 | } | |
| 511 | 512 | ||
| 513 | + | go func() { | |
| 514 | + | for key := range web.Cfg.CacheClearingQueue { | |
| 515 | + | rKey := filepath.Join(key, "_redirects") | |
| 516 | + | redirectsCache.Remove(rKey) | |
| 517 | + | hKey := filepath.Join(key, "_headers") | |
| 518 | + | headersCache.Remove(hKey) | |
| 519 | + | } | |
| 520 | + | }() | |
| 521 | + | ||
| 512 | 522 | asset := &ApiAssetHandler{ | |
| 513 | 523 | WebRouter: web, | |
| 514 | 524 | Logger: logger, |
+2
-2
pkg/apps/pgs/web_asset_handler.go
#
| ... | ... | @@ -49,7 +49,7 @@ func (h *ApiAssetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
| 49 | 49 | logger := h.Logger | |
| 50 | 50 | var redirects []*RedirectRule | |
| 51 | 51 | ||
| 52 | - | redirectsCacheKey := filepath.Join(h.Bucket.Name, h.ProjectDir, "_redirects") | |
| 52 | + | redirectsCacheKey := filepath.Join(getSurrogateKey(h.UserID, h.ProjectDir), "_redirects") | |
| 53 | 53 | if cachedRedirects, found := redirectsCache.Get(redirectsCacheKey); found { | |
| 54 | 54 | redirects = cachedRedirects | |
| 55 | 55 | } else { |
| ... | ... | @@ -179,7 +179,7 @@ func (h *ApiAssetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
| 179 | 179 | ||
| 180 | 180 | var headers []*HeaderRule | |
| 181 | 181 | ||
| 182 | - | headersCacheKey := filepath.Join(h.Bucket.Name, h.ProjectDir, "_headers") | |
| 182 | + | headersCacheKey := filepath.Join(getSurrogateKey(h.UserID, h.ProjectDir), "_headers") | |
| 183 | 183 | if cachedHeaders, found := headersCache.Get(headersCacheKey); found { | |
| 184 | 184 | headers = cachedHeaders | |
| 185 | 185 | } else { |
+21
-0
pkg/cache/cache.go
#
| ... | ... | @@ -0,0 +1,21 @@ | |
| 1 | + | package cache | |
| 2 | + | ||
| 3 | + | import ( | |
| 4 | + | "log/slog" | |
| 5 | + | "time" | |
| 6 | + | ||
| 7 | + | "github.com/picosh/utils" | |
| 8 | + | ) | |
| 9 | + | ||
| 10 | + | var CacheTimeout time.Duration | |
| 11 | + | ||
| 12 | + | func init() { | |
| 13 | + | cacheDuration := utils.GetEnv("STORAGE_MINIO_CACHE_DURATION", "1m") | |
| 14 | + | duration, err := time.ParseDuration(cacheDuration) | |
| 15 | + | if err != nil { | |
| 16 | + | slog.Error("Invalid STORAGE_MINIO_CACHE_DURATION value, using default 1m", "error", err) | |
| 17 | + | duration = 1 * time.Minute | |
| 18 | + | } | |
| 19 | + | ||
| 20 | + | CacheTimeout = duration | |
| 21 | + | } |