Skip to content

Commit

Permalink
feat: refactor cache service initialization and make cache durations …
Browse files Browse the repository at this point in the history
…configurable
  • Loading branch information
sundayonah committed Jan 28, 2025
1 parent 62bfcc6 commit 3bb24ef
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions routers/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ import (
// RegisterRoutes add all routing list here automatically get main router
func RegisterRoutes(route *gin.Engine) {
conf := config.RedisConfig()
serverConf := config.ServerConfig()

cacheService, err := middleware.NewCacheService(middleware.CacheConfig{
Host: conf.Host,
Port: conf.Port,
Password: conf.Password,
DB: conf.DB,
})
cacheService, err := middleware.NewCacheService(conf)
if err != nil {
log.Fatalf("Failed to initialize cache: %v", err)
}
Expand All @@ -45,16 +41,16 @@ func RegisterRoutes(route *gin.Engine) {

v1.GET(
"currencies",
cacheService.CacheMiddleware(24*time.Hour),
cacheService.CacheMiddleware(time.Duration(serverConf.CurrenciesCacheDuration)*time.Hour),
ctrl.GetFiatCurrencies,
)
v1.GET(
"institutions/:currency_code",
cacheService.CacheMiddleware(24*time.Hour),
cacheService.CacheMiddleware(time.Duration(serverConf.InstitutionsCacheDuration)*time.Hour),
ctrl.GetInstitutionsByCurrency,
)
v1.GET("pubkey",
cacheService.CacheMiddleware(365*24*time.Hour),
cacheService.CacheMiddleware(time.Duration(serverConf.PubKeyCacheDuration)*24*time.Hour),
ctrl.GetAggregatorPublicKey,
)

Expand Down

0 comments on commit 3bb24ef

Please sign in to comment.