Skip to content

Commit

Permalink
fix: Cache is usable without proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
dadav committed Jun 30, 2024
1 parent cc51d2f commit 4c82bae
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,16 @@ You can also enable the caching functionality to speed things up.`,
}
}

if config.FallbackProxyUrl != "" {
if !config.NoCache {
customKeyFunc := func(r *http.Request) uint64 {
token := r.Header.Get("Authorization")
return stampede.StringToHash(r.Method, strings.ToLower(token))
}
cachedMiddleware := stampede.HandlerWithKey(512, time.Duration(config.CacheMaxAge)*time.Second, customKeyFunc, strings.Split(config.CachePrefixes, ",")...)
r.Use(cachedMiddleware)
if !config.NoCache {
customKeyFunc := func(r *http.Request) uint64 {
token := r.Header.Get("Authorization")
return stampede.StringToHash(r.Method, strings.ToLower(token))
}
cachedMiddleware := stampede.HandlerWithKey(512, time.Duration(config.CacheMaxAge)*time.Second, customKeyFunc, strings.Split(config.CachePrefixes, ",")...)
r.Use(cachedMiddleware)
}

if config.FallbackProxyUrl != "" {

proxies := strings.Split(config.FallbackProxyUrl, ",")
slices.Reverse(proxies)
Expand Down

0 comments on commit 4c82bae

Please sign in to comment.