Skip to content

Commit

Permalink
Fix resolver cache
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicletz committed Sep 9, 2024
1 parent 083e464 commit f8054b1
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions rpc/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,12 @@ func (resolver *Resolver) ResolveDevice(deviceName string) (ret []*edge.DeviceTi

// Calling GetObject to locate the device
cachedDevice := resolver.datapool.GetCacheDevice(deviceID)
if cachedDevice != nil {
if cachedDevice.BlockNumber == 0 && time.Since(cachedDevice.CacheTime) < 8*time.Hour {
// The last time we checked there was no object (device was offline)
continue
} else if client.isRecentTicket(cachedDevice) {
if cachedDevice != nil && cachedDevice.Version != 0 {
if client.isRecentTicket(cachedDevice) {
ret = append(ret, cachedDevice)
fmt.Println("using cachedDevice", cachedDevice)
continue
} else if time.Since(cachedDevice.CacheTime) < 8*time.Hour {
} else if time.Since(cachedDevice.CacheTime) < 15*time.Minute {
// The ticket is not recent but the entry had been fetched recently
// So we skip re-fetching it, assuming there is no newer atm
continue
Expand All @@ -107,9 +105,9 @@ func (resolver *Resolver) ResolveDevice(deviceName string) (ret []*edge.DeviceTi

if !client.isRecentTicket(device) {
// Setting a nil to cache, to mark the current time of the last check
resolver.datapool.SetCacheDevice(deviceID, &edge.DeviceTicket{})
continue
resolver.datapool.SetCacheDevice(deviceID, device)
client.Log().Warn("found outdated deviceticket() %v", device)
continue
}

if device.BlockHash, err = client.ResolveBlockHash(device.BlockNumber); err != nil {
Expand Down

0 comments on commit f8054b1

Please sign in to comment.