mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-06 13:27:39 +03:00
Range func for lru cache
This commit is contained in:
parent
99754098d1
commit
494a87e9ee
1 changed files with 8 additions and 0 deletions
8
common/cache/lrucache.go
vendored
8
common/cache/lrucache.go
vendored
|
@ -216,6 +216,14 @@ func (c *LruCache[K, V]) CloneTo(n *LruCache[K, V]) {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *LruCache[K, V]) Range(block func(key K, value V)) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
for le := c.lru.Front(); le != nil; le = le.Next() {
|
||||
block(le.Value.key, le.Value.value)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *LruCache[K, V]) get(key K) *entry[K, V] {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue