Skip to content

Commit 5fe9b9f

Browse files
Fix cache clear. Closes #520 (#521)
Co-authored-by: kai <[email protected]>
1 parent a618266 commit 5fe9b9f

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

hub/hub_base.go

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,20 @@ package hub
33
import (
44
"context"
55
"fmt"
6-
"log"
7-
"strings"
8-
"sync"
9-
"time"
10-
11-
"github.com/turbot/steampipe/pkg/query/queryresult"
12-
136
"github.com/turbot/go-kit/helpers"
147
"github.com/turbot/steampipe-plugin-sdk/v5/grpc"
158
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
169
"github.com/turbot/steampipe-plugin-sdk/v5/telemetry"
1710
"github.com/turbot/steampipe-postgres-fdw/settings"
1811
"github.com/turbot/steampipe-postgres-fdw/types"
1912
"github.com/turbot/steampipe/pkg/constants"
13+
"github.com/turbot/steampipe/pkg/query/queryresult"
2014
"go.opentelemetry.io/otel"
2115
"go.opentelemetry.io/otel/attribute"
2216
"go.opentelemetry.io/otel/metric"
17+
"log"
18+
"strings"
19+
"sync"
2320
)
2421

2522
type hubBase struct {
@@ -520,20 +517,6 @@ func (h *hubBase) HandleLegacyCacheCommand(command string) error {
520517
return nil
521518
}
522519

523-
func (h *hubBase) cacheTTL(connectionName string) time.Duration {
524-
log.Printf("[INFO] cacheTTL 1")
525-
// if the cache ttl has been overridden, then enforce the value
526-
if h.cacheSettings.Ttl != nil {
527-
return *h.cacheSettings.Ttl
528-
}
529-
log.Printf("[INFO] cacheTTL 2")
530-
531-
const defaultTtl = 300 * time.Second
532-
533-
log.Printf("[INFO] default cacheTTL %v", defaultTtl)
534-
return defaultTtl
535-
}
536-
537520
// GetSortableFields
538521
func (h *hubBase) GetSortableFields(tableName, connectionName string) map[string]proto.SortOrder {
539522
return nil

hub/hub_remote.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,16 +300,19 @@ func (h *RemoteHub) cacheEnabled(connectionName string) bool {
300300
}
301301

302302
func (h *RemoteHub) cacheTTL(connectionName string) time.Duration {
303+
// initialise to default
304+
ttl := 300 * time.Second
303305
// if the cache ttl has been overridden, then enforce the value
304306
if h.cacheSettings.Ttl != nil {
305-
return *h.cacheSettings.Ttl
307+
ttl = *h.cacheSettings.Ttl
308+
}
309+
// would this give data earlier than the cacheClearTime
310+
now := time.Now()
311+
if now.Add(-ttl).Before(h.cacheSettings.ClearTime) {
312+
ttl = now.Sub(h.cacheSettings.ClearTime)
306313
}
307314

308-
// default ttl is 300 secs
309-
const defaultTTL = 300 * time.Second
310-
311-
log.Printf("[INFO] default cacheTTL returning %v", defaultTTL)
312-
return defaultTTL
315+
return ttl
313316
}
314317

315318
// resolve the server cache enabled property

0 commit comments

Comments
 (0)