Skip to content

Commit

Permalink
Fix cache clear. Closes #520 (#521)
Browse files Browse the repository at this point in the history
Co-authored-by: kai <[email protected]>
  • Loading branch information
pskrbasu and kaidaguerre authored Nov 20, 2024
1 parent a618266 commit 5fe9b9f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
25 changes: 4 additions & 21 deletions hub/hub_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@ 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"
"github.com/turbot/steampipe-plugin-sdk/v5/telemetry"
"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 {
Expand Down Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions hub/hub_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5fe9b9f

Please sign in to comment.