diff --git a/pkg/uhttp/wrapper.go b/pkg/uhttp/wrapper.go index 94640f69..ebcf5233 100644 --- a/pkg/uhttp/wrapper.go +++ b/pkg/uhttp/wrapper.go @@ -98,11 +98,6 @@ func NewBaseHttpClientWithContext(ctx context.Context, httpClient *http.Client) cacheMaxSize = 128 // MB } - memoryCache, err := strconv.ParseBool(os.Getenv("BATON_IN_MEMORY_HTTP_CACHE")) - if err != nil { - memoryCache = false - } - var ( config = CacheConfig{ LogDebug: l.Level().Enabled(zap.DebugLevel), @@ -121,25 +116,32 @@ func NewBaseHttpClientWithContext(ctx context.Context, httpClient *http.Client) } } - // in-memory cache - if memoryCache { - memCache, err := NewGoCache(ctx, config) - if err != nil { - l.Error("error creating http cache(in-memory)", zap.Error(err)) - return nil, err + if !disableCache { + cacheBackend := os.Getenv("BATON_HTTP_CACHE_BACKEND") + if cacheBackend == "" { + cacheBackend = "db" } - cli.baseHttpCache = &memCache - return cli, nil - } - // db-cache(Default) - cache, err := NewDBCache(ctx, config) - if err != nil { - l.Error("error creating http cache(db-cache)", zap.Error(err)) - return nil, err + switch cacheBackend { + case "memory": + memCache, err := NewGoCache(ctx, config) + if err != nil { + l.Error("error creating http cache (in-memory)", zap.Error(err)) + return nil, err + } + cli.baseHttpCache = &memCache + case "db": + cache, err := NewDBCache(ctx, config) + if err != nil { + l.Error("error creating http cache (db-cache)", zap.Error(err)) + return nil, err + } + cli.baseHttpCache = cache + default: + return nil, fmt.Errorf("unsupported cache backend: %s", cacheBackend) + } } - cli.baseHttpCache = cache return cli, nil }