Finally - fixed the cache version for single query if its enabled via header.

This commit is contained in:
2023-04-08 03:25:33 +01:00
parent 841c136e71
commit 55182f2f3d
3 changed files with 73 additions and 8 deletions
+10 -6
View File
@@ -4,6 +4,7 @@ import (
"crypto/tls"
"time"
"github.com/allegro/bigcache"
"github.com/lukaszraczylo/go-simple-graphql/utils/concurrency"
"github.com/lukaszraczylo/go-simple-graphql/utils/logger"
@@ -14,7 +15,6 @@ import (
"os"
"strings"
"github.com/allegro/bigcache"
"github.com/gookit/goutil/envutil"
)
@@ -43,11 +43,7 @@ func NewConnection() *BaseClient {
b.retries.delay = envutil.GetInt("GRAPHQL_RETRIES_DELAY", 300)
if b.cache.enabled {
var err error
b.cache.client, err = bigcache.NewBigCache(bigcache.DefaultConfig(time.Duration(b.cache.ttl) * time.Second))
if err != nil {
b.Logger.Error(b, "Error while creating cache client;", "error", err.Error())
}
b.enableCache()
}
b_tmp_log_level := envutil.Getenv("LOG_LEVEL", "info")
@@ -102,3 +98,11 @@ func (b *BaseClient) SetEndpoint(endpoint string) {
func (b *BaseClient) SetOutput(output string) {
b.responseType = output
}
func (b *BaseClient) enableCache() {
var err error
b.cache.client, err = bigcache.NewBigCache(bigcache.DefaultConfig(time.Duration(b.cache.ttl) * time.Second))
if err != nil {
b.Logger.Error(b, "Error while creating cache client;", "error", err.Error())
}
}