MM-20104 -Migrate channelCache cache from store/sqlstore/channel_store.go to th… (#13254)

* Migrate channelCache cache from store/sqlstore/channel_store.go to the new store/localcachelayer

* fix import for new path

* remove unnecessary code, refactor cache constant

* resolve conflicts

* fix missing variable and import after merging

* refactor code, fix current issue

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Vladimir Lebedev
2019-12-20 11:04:58 +03:00
коммит произвёл Agniva De Sarker
родитель 722924b910
Коммит e4481aae21
5 изменённых файлов: 106 добавлений и 22 удалений

Просмотреть файл

@@ -276,19 +276,16 @@ type publicChannel struct {
var allChannelMembersForUserCache = utils.NewLru(ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SIZE)
var allChannelMembersNotifyPropsForChannelCache = utils.NewLru(ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_SIZE)
var channelCache = utils.NewLru(model.CHANNEL_CACHE_SIZE)
var channelByNameCache = utils.NewLru(model.CHANNEL_CACHE_SIZE)
func (s SqlChannelStore) ClearCaches() {
allChannelMembersForUserCache.Purge()
allChannelMembersNotifyPropsForChannelCache.Purge()
channelCache.Purge()
channelByNameCache.Purge()
if s.metrics != nil {
s.metrics.IncrementMemCacheInvalidationCounter("All Channel Members for User - Purge")
s.metrics.IncrementMemCacheInvalidationCounter("All Channel Members Notify Props for Channel - Purge")
s.metrics.IncrementMemCacheInvalidationCounter("Channel - Purge")
s.metrics.IncrementMemCacheInvalidationCounter("Channel By Name - Purge")
}
}
@@ -661,10 +658,6 @@ func (s SqlChannelStore) GetChannelUnread(channelId, userId string) (*model.Chan
}
func (s SqlChannelStore) InvalidateChannel(id string) {
channelCache.Remove(id)
if s.metrics != nil {
s.metrics.IncrementMemCacheInvalidationCounter("Channel - Remove by ChannelId")
}
}
func (s SqlChannelStore) InvalidateChannelByName(teamId, name string) {
@@ -705,20 +698,6 @@ func (s SqlChannelStore) get(id string, master bool, allowFromCache bool) (*mode
db = s.GetReplica()
}
if allowFromCache {
if cacheItem, ok := channelCache.Get(id); ok {
if s.metrics != nil {
s.metrics.IncrementMemCacheHitCounter("Channel")
}
ch := cacheItem.(*model.Channel).DeepCopy()
return ch, nil
}
}
if s.metrics != nil {
s.metrics.IncrementMemCacheMissCounter("Channel")
}
obj, err := db.Get(model.Channel{}, id)
if err != nil {
return nil, model.NewAppError("SqlChannelStore.Get", "store.sql_channel.get.find.app_error", nil, "id="+id+", "+err.Error(), http.StatusInternalServerError)
@@ -729,7 +708,6 @@ func (s SqlChannelStore) get(id string, master bool, allowFromCache bool) (*mode
}
ch := obj.(*model.Channel)
channelCache.AddWithExpiresInSecs(id, ch, CHANNEL_CACHE_SEC)
return ch, nil
}