mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-07-15 22:41:14 +00:00
refactor: rework rate limit logic (#1008)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user