Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
trajan0x committed May 4, 2024
1 parent 43ff96b commit b555699
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions services/rfq/api/rest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,18 @@ func NewAPI(
roles[chainID] = ttlcache.New[string, bool](
ttlcache.WithTTL[string, bool](cacheInterval),
)
// purge periodically
const cachePurgeInterval = 5 * time.Second
cacheTimer := time.NewTimer(cachePurgeInterval)

roleCache := roles[chainID]

go func() {
select {
case <-ctx.Done():
cacheTimer.Stop()
case <-cacheTimer.C:
cacheTimer.Reset(cachePurgeInterval)
roleCache.DeleteExpired()
}
}()

roleCache.Start()
}

go func() {
<-ctx.Done()
for _, roleCache := range roles {
roleCache.Stop()
}
}()

return &QuoterAPIServer{
cfg: cfg,
db: store,
Expand Down

0 comments on commit b555699

Please sign in to comment.