Skip to content

Commit

Permalink
move clearing to get calls
Browse files Browse the repository at this point in the history
  • Loading branch information
3u13r committed Jan 3, 2024
1 parent 19bcb36 commit 010f4e0
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions internal/attestation/snp/cachedClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ func NewCachedKDSHTTPClient(ticker clock.Ticker, log *slog.Logger) *cachedKDSHTT
gcTicker: ticker,
}

go c.garbageCollect()
return c
}

func (c *cachedKDSHTTPClient) Get(url string) ([]byte, error) {
select {
case <-c.gcTicker.C():
c.logger.Debug("Garbage collecting")
c.cache.Clear()
default:
}

if cached, ok := c.cache.Get(url); ok {
c.logger.Debug("Get cached", "url", url)
return cached, nil
Expand All @@ -44,10 +50,3 @@ func (c *cachedKDSHTTPClient) Get(url string) ([]byte, error) {
c.cache.Set(url, res)
return res, nil
}

func (c *cachedKDSHTTPClient) garbageCollect() {
for range c.gcTicker.C() {
c.logger.Debug("Garbage collecting")
c.cache.Clear()
}
}

0 comments on commit 010f4e0

Please sign in to comment.