pico

created pr with 59.1 on 2025-04-06T03:01:44Z · by c8ef7d19
added 59.2 on 2025-04-06T03:03:49Z · by c8ef7d19
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 on 2025-04-06T19:08:31Z · by c8ef7d19
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 on 2025-04-06T19:41:38Z · by c8ef7d19
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 -3
checkout any patchset in a patch request:
ssh pr.pico.sh print 59.[rev] | git am -3
add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 59
+12 -2 pkg/apps/pgs/web.go #
......@@ -75,7 +75,7 @@ func StartApiServer(cfg *PgsConfig) {
7575 routes: routes,
7676 }
7777
78- go routes.cacheMgmt(ctx, httpCache)
78+ go routes.cacheMgmt(ctx, httpCache, cfg.CacheClearingQueue)
7979
8080 portStr := fmt.Sprintf(":%s", cfg.WebPort)
8181 cfg.Logger.Info(
......@@ -260,7 +260,7 @@ func (web *WebRouter) checkHandler(w http.ResponseWriter, r *http.Request) {
260260 w.WriteHeader(http.StatusNotFound)
261261 }
262262
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) {
264264 storer := httpCache.Storers[0]
265265 drain := createSubCacheDrain(ctx, web.Cfg.Logger)
266266
......@@ -270,6 +270,7 @@ func (web *WebRouter) cacheMgmt(ctx context.Context, httpCache *middleware.Souin
270270 for scanner.Scan() {
271271 surrogateKey := strings.TrimSpace(scanner.Text())
272272 web.Cfg.Logger.Info("received cache-drain item", "surrogateKey", surrogateKey)
273+ notify <- surrogateKey
273274
274275 if surrogateKey == "*" {
275276 storer.DeleteMany(".+")
......@@ -509,6 +510,15 @@ func (web *WebRouter) ServeAsset(fname string, opts *storage.ImgProcessOpts, fro
509510 }
510511 }
511512
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+
512522 asset := &ApiAssetHandler{
513523 WebRouter: web,
514524 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) {
4949 logger := h.Logger
5050 var redirects []*RedirectRule
5151
52- redirectsCacheKey := filepath.Join(h.Bucket.Name, h.ProjectDir, "_redirects")
52+ redirectsCacheKey := filepath.Join(getSurrogateKey(h.UserID, h.ProjectDir), "_redirects")
5353 if cachedRedirects, found := redirectsCache.Get(redirectsCacheKey); found {
5454 redirects = cachedRedirects
5555 } else {
......@@ -179,7 +179,7 @@ func (h *ApiAssetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
179179
180180 var headers []*HeaderRule
181181
182- headersCacheKey := filepath.Join(h.Bucket.Name, h.ProjectDir, "_headers")
182+ headersCacheKey := filepath.Join(getSurrogateKey(h.UserID, h.ProjectDir), "_headers")
183183 if cachedHeaders, found := headersCache.Get(headersCacheKey); found {
184184 headers = cachedHeaders
185185 } 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+}
Back to top