Skip to content

Commit

Permalink
fix caching
Browse files Browse the repository at this point in the history
  • Loading branch information
pskrbasu committed Oct 7, 2024
1 parent 15aa056 commit ee14c21
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
11 changes: 3 additions & 8 deletions hub/hub_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,15 +528,10 @@ func (h *hubBase) cacheTTL(connectionName string) time.Duration {
}
log.Printf("[INFO] cacheTTL 2")

var ttl time.Duration
const defaultTtl = 300 * time.Second

// 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)
}
log.Printf("[INFO] cacheTTL 5")
return ttl
log.Printf("[INFO] default cacheTTL %v", defaultTtl)
return defaultTtl
}

// GetSortableFields
Expand Down
14 changes: 7 additions & 7 deletions hub/hub_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,15 @@ func (h *RemoteHub) clearConnectionCache(connection string) error {
func (h *RemoteHub) cacheEnabled(connectionName string) bool {
// if the caching is disabled for the server, just return false
if !h.cacheSettings.ServerCacheEnabled {
log.Printf("[INFO] cacheEnabled returning false since server cache is disabled")
return false
}

if h.cacheSettings.ClientCacheEnabled != nil {
log.Printf("[INFO] cacheEnabled returning %v since client cache is enabled", *h.cacheSettings.ClientCacheEnabled)
return *h.cacheSettings.ClientCacheEnabled
}
log.Printf("[INFO] default cacheEnabled returning true")

return true
}
Expand All @@ -302,14 +305,11 @@ func (h *RemoteHub) cacheTTL(connectionName string) time.Duration {
return *h.cacheSettings.Ttl
}

var ttl time.Duration
// default ttl is 300 secs
const defaultTTL = 300 * time.Second

// 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)
}
return ttl
log.Printf("[INFO] default cacheTTL returning %v", defaultTTL)
return defaultTTL
}

// resolve the server cache enabled property
Expand Down

0 comments on commit ee14c21

Please sign in to comment.