Skip to content

Commit 070ffcb

Browse files
authored
Add ParseCacheConfigPaths (#70)
* Fix cache middleware and minor fix on logger * add ParseCacheConfigPaths
1 parent 932b369 commit 070ffcb

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkg/zrouter/zmiddlewares/cache.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,17 @@ func cacheResponseIfNeeded(rw *responseWriter, r *http.Request, cache zcache.ZCa
7575
logger.GetLoggerFromContext(r.Context()).Errorf("Internal error when setting cache response: %v\n%s", err, debug.Stack())
7676
}
7777
}
78+
79+
func ParseCacheConfigPaths(paths map[string]string) (domain.CacheConfig, error) {
80+
parsedPaths := make(map[string]time.Duration)
81+
82+
for path, ttlStr := range paths {
83+
ttl, err := time.ParseDuration(ttlStr)
84+
if err != nil {
85+
return domain.CacheConfig{}, fmt.Errorf("error parsing TTL duration for the path %s: %w", path, err)
86+
}
87+
parsedPaths[path] = ttl
88+
}
89+
90+
return domain.CacheConfig{Paths: parsedPaths}, nil
91+
}

0 commit comments

Comments
 (0)