MM-25115- migrate post, session and status cache to cache2 (#14667)

* use cache2.Provider cache

* use cache2.Provider cache

* clean up imports

* reset test runner

* add close() call

* Fixing i18n

* address review comments

Co-authored-by: Jesús Espino <jespinog@gmail.com>
Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Siyuan Liu
2020-06-02 05:17:00 -04:00
коммит произвёл GitHub
родитель beadeaf8b5
Коммит c183a5d380
6 изменённых файлов: 83 добавлений и 49 удалений

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

@@ -6,6 +6,7 @@ package app
import (
"math"
"net/http"
"time"
"github.com/mattermost/mattermost-server/v5/audit"
"github.com/mattermost/mattermost-server/v5/mlog"
@@ -30,8 +31,7 @@ func (a *App) GetSession(token string) (*model.Session, *model.AppError) {
var session *model.Session
var err *model.AppError
if ts, ok := a.Srv().sessionCache.Get(token); ok {
session = ts.(*model.Session)
if err := a.Srv().sessionCache.Get(token, &session); err == nil {
if metrics != nil {
metrics.IncrementMemCacheHitCounterSession()
}
@@ -178,15 +178,15 @@ func (a *App) ClearSessionCacheForAllUsers() {
}
func (a *App) ClearSessionCacheForUserSkipClusterSend(userId string) {
keys := a.Srv().sessionCache.Keys()
for _, key := range keys {
if ts, ok := a.Srv().sessionCache.Get(key); ok {
session := ts.(*model.Session)
if session.UserId == userId {
a.Srv().sessionCache.Remove(key)
if a.Metrics() != nil {
a.Metrics().IncrementMemCacheInvalidationCounterSession()
if keys, err := a.Srv().sessionCache.Keys(); err == nil {
var session *model.Session
for _, key := range keys {
if err := a.Srv().sessionCache.Get(key, &session); err == nil {
if session.UserId == userId {
a.Srv().sessionCache.Remove(key)
if a.Metrics() != nil {
a.Metrics().IncrementMemCacheInvalidationCounterSession()
}
}
}
}
@@ -201,11 +201,14 @@ func (a *App) ClearSessionCacheForAllUsersSkipClusterSend() {
}
func (a *App) AddSessionToCache(session *model.Session) {
a.Srv().sessionCache.AddWithExpiresInSecs(session.Token, session, int64(*a.Config().ServiceSettings.SessionCacheInMinutes*60))
a.Srv().sessionCache.SetWithExpiry(session.Token, session, time.Duration(int64(*a.Config().ServiceSettings.SessionCacheInMinutes))*time.Minute)
}
func (a *App) SessionCacheLength() int {
return a.Srv().sessionCache.Len()
if l, err := a.Srv().sessionCache.Len(); err == nil {
return l
}
return 0
}
func (a *App) RevokeSessionsForDeviceId(userId string, deviceId string, currentSessionId string) *model.AppError {