refactor: rework rate limit logic (#1008)

This commit is contained in:
Stavros
2026-07-15 15:30:57 +03:00
committed by GitHub
parent 6e095fd4f2
commit dade1e2c8f
7 changed files with 78 additions and 120 deletions
+16
View File
@@ -195,3 +195,19 @@ func (cs *CacheStore[T]) Clear() {
cs.cache = make(map[string]cacheEntry[T])
cs.order = make([]string, 0)
}
func (cs *CacheStore[T]) SetMaxSize(maxSize int) {
cs.mu.Lock()
defer cs.mu.Unlock()
cs.maxSize = maxSize
for len(cs.cache) > maxSize {
if !cs.evictOne() {
break
}
}
}
func (cs *CacheStore[T]) GetMaxSize() int {
cs.mu.Lock()
defer cs.mu.Unlock()
return cs.maxSize
}