Skip to content

Commit

Permalink
refactor(oracle): simplify caching logic in GetRealtimeICYBTC
Browse files Browse the repository at this point in the history
  • Loading branch information
lmquang committed Feb 28, 2025
1 parent 67d4dee commit a310184
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions internal/oracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ func (o *IcyOracle) GetRealtimeICYBTC() (*model.Web3BigInt, error) {
o.cacheMux.Lock()
defer o.cacheMux.Unlock()

// Try to get from cache first
if cachedRate, found := o.cache.Get("icysat_rate"); found {
if rate, ok := cachedRate.(*model.Web3BigInt); ok {
return rate, nil
}
}

// If not in cache, calculate
circulatedICY, err := o.GetCirculatedICY()
if err != nil {
Expand Down Expand Up @@ -128,6 +121,12 @@ func (o *IcyOracle) GetRealtimeICYBTC() (*model.Web3BigInt, error) {
}

func (o *IcyOracle) GetCachedRealtimeICYBTC() (*model.Web3BigInt, error) {
// This method now simply calls GetRealtimeICYBTC, which already handles caching
// Try to get from cache first
if cachedRate, found := o.cache.Get("icysat_rate"); found {
if rate, ok := cachedRate.(*model.Web3BigInt); ok {
return rate, nil
}
}

return o.GetRealtimeICYBTC()
}

0 comments on commit a310184

Please sign in to comment.