Skip to content

Commit

Permalink
Refactoring code
Browse files Browse the repository at this point in the history
  • Loading branch information
mchavez committed Aug 29, 2024
1 parent 08a376f commit a259b91
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/uhttp/dbcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type ICache interface {
}

type DBCache struct {
db *sql.DB
defaultExpiration time.Duration
db *sql.DB
expiration int32
}

type Stats struct {
Expand Down Expand Up @@ -91,19 +91,19 @@ func NewDBCache(ctx context.Context, cfg CacheConfig) (*DBCache, error) {
}

dc := &DBCache{
defaultExpiration: cfg.ExpirationTime,
db: db,
expiration: 180, // 3 hours
db: db,
}

if cfg.NoExpiration > 0 {
go func() {
go func(expiration int32) {
ctxWithTimeout, cancel := context.WithTimeout(
ctx,
time.Duration(180)*time.Minute,
time.Duration(expiration)*time.Minute,
)
defer cancel()

ticker := time.NewTicker(dc.defaultExpiration)
ticker := time.NewTicker(cfg.ExpirationTime)
defer ticker.Stop()
for {
select {
Expand All @@ -122,7 +122,7 @@ func NewDBCache(ctx context.Context, cfg CacheConfig) (*DBCache, error) {
}
}
}
}()
}(dc.expiration)
}

return dc, nil
Expand Down

0 comments on commit a259b91

Please sign in to comment.