diff --git a/hub/hub_base.go b/hub/hub_base.go index 7b91923b..6ba59938 100644 --- a/hub/hub_base.go +++ b/hub/hub_base.go @@ -3,13 +3,6 @@ package hub import ( "context" "fmt" - "log" - "strings" - "sync" - "time" - - "github.com/turbot/steampipe/pkg/query/queryresult" - "github.com/turbot/go-kit/helpers" "github.com/turbot/steampipe-plugin-sdk/v5/grpc" "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" @@ -17,9 +10,13 @@ import ( "github.com/turbot/steampipe-postgres-fdw/settings" "github.com/turbot/steampipe-postgres-fdw/types" "github.com/turbot/steampipe/pkg/constants" + "github.com/turbot/steampipe/pkg/query/queryresult" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" + "log" + "strings" + "sync" ) type hubBase struct { @@ -520,20 +517,6 @@ func (h *hubBase) HandleLegacyCacheCommand(command string) error { return nil } -func (h *hubBase) cacheTTL(connectionName string) time.Duration { - log.Printf("[INFO] cacheTTL 1") - // if the cache ttl has been overridden, then enforce the value - if h.cacheSettings.Ttl != nil { - return *h.cacheSettings.Ttl - } - log.Printf("[INFO] cacheTTL 2") - - const defaultTtl = 300 * time.Second - - log.Printf("[INFO] default cacheTTL %v", defaultTtl) - return defaultTtl -} - // GetSortableFields func (h *hubBase) GetSortableFields(tableName, connectionName string) map[string]proto.SortOrder { return nil diff --git a/hub/hub_remote.go b/hub/hub_remote.go index 848bab17..825e462a 100644 --- a/hub/hub_remote.go +++ b/hub/hub_remote.go @@ -300,16 +300,19 @@ func (h *RemoteHub) cacheEnabled(connectionName string) bool { } func (h *RemoteHub) cacheTTL(connectionName string) time.Duration { + // initialise to default + ttl := 300 * time.Second // if the cache ttl has been overridden, then enforce the value if h.cacheSettings.Ttl != nil { - return *h.cacheSettings.Ttl + ttl = *h.cacheSettings.Ttl + } + // would this give data earlier than the cacheClearTime + now := time.Now() + if now.Add(-ttl).Before(h.cacheSettings.ClearTime) { + ttl = now.Sub(h.cacheSettings.ClearTime) } - // default ttl is 300 secs - const defaultTTL = 300 * time.Second - - log.Printf("[INFO] default cacheTTL returning %v", defaultTTL) - return defaultTTL + return ttl } // resolve the server cache enabled property