mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-03 20:07:38 +03:00
Add LRUCache.Clear
This commit is contained in:
parent
620f3a3b88
commit
8d731e6885
1 changed files with 8 additions and 0 deletions
8
common/cache/lrucache.go
vendored
8
common/cache/lrucache.go
vendored
|
@ -258,6 +258,14 @@ func (c *LruCache[K, V]) Delete(key K) {
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *LruCache[K, V]) Clear() {
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
|
for element := c.lru.Front(); element != nil; element = element.Next() {
|
||||||
|
c.deleteElement(element)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *LruCache[K, V]) maybeDeleteOldest() {
|
func (c *LruCache[K, V]) maybeDeleteOldest() {
|
||||||
if !c.staleReturn && c.maxAge > 0 {
|
if !c.staleReturn && c.maxAge > 0 {
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue