Compare commits

...
2 Commits
+7 -3
View File
@@ -92,7 +92,7 @@ func (c *BaseClient) Query(queryContent string, queryVariables interface{}, quer
queryHash = strutil.Md5(fmt.Sprintf("%s-%+v", query.compiledQuery, queryHeaders)) queryHash = strutil.Md5(fmt.Sprintf("%s-%+v", query.compiledQuery, queryHeaders))
cacheBaseClient.Logger.Debug(cacheBaseClient, "Hash calculated;", "hash:", queryHash) cacheBaseClient.Logger.Debug(cacheBaseClient, "Hash calculated;", "hash:", queryHash)
cachedResponse = cacheBaseClient.cacheLookup(queryHash) cachedResponse = c.cacheLookup(queryHash)
if cachedResponse != nil { if cachedResponse != nil {
cacheBaseClient.Logger.Debug(cacheBaseClient, "Found cached response") cacheBaseClient.Logger.Debug(cacheBaseClient, "Found cached response")
return cacheBaseClient.decodeResponse(cachedResponse), nil return cacheBaseClient.decodeResponse(cachedResponse), nil
@@ -113,8 +113,12 @@ func (c *BaseClient) Query(queryContent string, queryVariables interface{}, quer
return nil, err return nil, err
} }
if cacheBaseClient.cache.enabled { if cacheBaseClient.cache.enabled && jsonData != nil && queryHash != "" {
cacheBaseClient.cache.client.Set(queryHash, jsonData) c.cache.client.Set(queryHash, jsonData)
} else if jsonData == nil {
cacheBaseClient.Logger.Warn(cacheBaseClient, "Response is empty")
} else if queryHash == "" {
cacheBaseClient.Logger.Warn(cacheBaseClient, "Query hash is empty")
} }
return cacheBaseClient.decodeResponse(jsonData), err return cacheBaseClient.decodeResponse(jsonData), err