Add in-memory cache #5
1 changed files with 2 additions and 1 deletions
3
cache/cache.go
vendored
3
cache/cache.go
vendored
|
@ -69,12 +69,13 @@ func (sc *ScoreCache) Add(score float64, ip netip.Addr, ts time.Time) {
|
|||
func (lc *ScoreCache) Get(ip netip.Addr) (ServerScore, error) {
|
||||
now := time.Now()
|
||||
lc.mu.RLock()
|
||||
defer lc.mu.RUnlock()
|
||||
|
||||
cachedScore, ok := lc.scores[ip]
|
||||
if !ok {
|
||||
lc.mu.RUnlock()
|
||||
return ServerScore{}, newCacheMissError()
|
||||
}
|
||||
lc.mu.RUnlock()
|
||||
|
||||
if now.After(cachedScore.expiresAt) {
|
||||
lc.delete(ip)
|
||||
|
|
Loading…
Reference in a new issue