Skip to content

Commit

Permalink
cache no candidate or ranked routes
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn committed Apr 19, 2024
1 parent 22a251b commit 94d44b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

# Changelog

## v0.17.4

- Cache no candidate or ranked routes

## v0.17.3

- Skip pool filtering if min osmo liquidity is zero
Expand Down
9 changes: 8 additions & 1 deletion router/usecase/router_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var (
cacheWrite = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "sqs_routes_cache_write_total",
Help: "Total number of cache misses",
Help: "Total number of cache writes",
},
[]string{"route", "cache_type", "token_in", "token_out", "token_in_order_of_magnitude"},
)
Expand Down Expand Up @@ -291,6 +291,13 @@ func (r *routerUseCaseImpl) computeAndRankRoutesByDirectQuote(ctx context.Contex
cacheWrite.WithLabelValues(requestURLPath, candidateRouteCacheLabel, tokenIn.Denom, tokenOutDenom, noOrderOfMagnitude).Inc()

r.candidateRouteCache.Set(formatCandidateRouteCacheKey(tokenIn.Denom, tokenOutDenom), candidateRoutes, time.Duration(routingOptions.CandidateRouteCacheExpirySeconds)*time.Second)
} else {
// If no candidate routes found, cache them for quarter of the duration
r.candidateRouteCache.Set(formatCandidateRouteCacheKey(tokenIn.Denom, tokenOutDenom), candidateRoutes, time.Duration(routingOptions.CandidateRouteCacheExpirySeconds/4)*time.Second)

r.rankedRouteCache.Set(formatRankedRouteCacheKey(tokenIn.Denom, tokenOutDenom, tokenInOrderOfMagnitude), candidateRoutes, time.Duration(routingOptions.RankedRouteCacheExpirySeconds/4)*time.Second)

return nil, nil, fmt.Errorf("no candidate routes found")
}

// Rank candidate routes by estimating direct quotes
Expand Down

0 comments on commit 94d44b8

Please sign in to comment.