MM-21210: Add LRU cache for ChannelStore.GetMembersForUser (#13593)

Automatic Merge
Этот коммит содержится в:
Agniva De Sarker
2020-01-13 21:16:51 +05:30
коммит произвёл mattermod
родитель 8b24b26cb0
Коммит 0361e8b97e
8 изменённых файлов: 314 добавлений и 27 удалений

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 поставляемый
Просмотреть файл

@@ -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()