MM-21210: Add LRU cache for ChannelStore.GetMembersForUser (#13593)
Automatic Merge
Этот коммит содержится в:
коммит произвёл
mattermod
родитель
8b24b26cb0
Коммит
0361e8b97e
3
services/cache/cache.go
поставляемый
3
services/cache/cache.go
поставляемый
@@ -31,6 +31,9 @@ type Cache interface {
|
||||
// Remove deletes the value for a key.
|
||||
Remove(key interface{})
|
||||
|
||||
// RemoveByPrefix deletes all keys containing the given prefix string.
|
||||
RemoveByPrefix(prefix string)
|
||||
|
||||
// Keys returns a slice of the keys in the cache.
|
||||
Keys() []interface{}
|
||||
|
||||
|
||||
19
services/cache/lru/lru.go
поставляемый
19
services/cache/lru/lru.go
поставляемый
@@ -12,6 +12,7 @@ package lru
|
||||
|
||||
import (
|
||||
"container/list"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -187,6 +188,24 @@ func (c *Cache) Remove(key interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
// RemoveByPrefix deletes all keys containing the given prefix string.
|
||||
func (c *Cache) RemoveByPrefix(prefix string) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
for ent := c.evictList.Back(); ent != nil; ent = ent.Prev() {
|
||||
e := ent.Value.(*entry)
|
||||
if e.generation == c.currentGeneration {
|
||||
keyString := e.key.(string)
|
||||
if strings.HasPrefix(keyString, prefix) {
|
||||
if ent, ok := c.items[e.key]; ok {
|
||||
c.removeElement(ent)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Keys returns a slice of the keys in the cache, from oldest to newest.
|
||||
func (c *Cache) Keys() []interface{} {
|
||||
c.lock.RLock()
|
||||
|
||||
Ссылка в новой задаче
Block a user