feat(botfilter): cache.go part 5/5
This commit is contained in:
1 parent
4cae994a89
commit
4033c254dc
1 file changed
+18
@@ -196,3 +196,21 @@ func (c *clientCache) ensureCapacityLocked(now time.Time) {
|
||||
return
|
||||
}
|
||||
|
||||
// Evict the oldest non-banned entry first. If all entries are banned, the
|
||||
// oldest ban is evicted; the cap remains a hard upper bound either way.
|
||||
var oldestIP string
|
||||
var oldestTime time.Time
|
||||
for ip, state := range c.entries {
|
||||
candidate := state.lastSeen
|
||||
if state.banUntil.After(now) {
|
||||
candidate = state.banUntil
|
||||
}
|
||||
if oldestIP == "" || candidate.Before(oldestTime) {
|
||||
oldestIP, oldestTime = ip, candidate
|
||||
}
|
||||
}
|
||||
if oldestIP != "" {
|
||||
delete(c.entries, oldestIP)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user