MM-56987: Improve cache API (#26298)
This is in preparation to make the codebase ready to use Redis. In Redis, iterating all the keys at once is an expensive operation. It is recommended to work on batches of keys. Remove the Len method as it was unused. I tried to repurpose the Keys method to iterate on keys rather than returning all keys at once, but it has other complicacies because the code calls other cache functions on those keys, so to handle the LRU cache properly, it becomes slightly more painful. For now, we keep it like this and rather collect all keys from Redis and then return. https://mattermost.atlassian.net/browse/MM-56987 ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
75e32051c4
Коммит
f9861b8666
@@ -45,13 +45,6 @@ func (ps *PlatformService) AddSessionToCache(session *model.Session) {
|
||||
ps.sessionCache.SetWithExpiry(session.Token, session, time.Duration(int64(*ps.Config().ServiceSettings.SessionCacheInMinutes))*time.Minute)
|
||||
}
|
||||
|
||||
func (ps *PlatformService) SessionCacheLength() int {
|
||||
if l, err := ps.sessionCache.Len(); err == nil {
|
||||
return l
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (ps *PlatformService) ClearUserSessionCacheLocal(userID string) {
|
||||
if keys, err := ps.sessionCache.Keys(); err == nil {
|
||||
var session *model.Session
|
||||
|
||||
@@ -47,11 +47,9 @@ func (s LocalCacheTermsOfServiceStore) Save(termsOfService *model.TermsOfService
|
||||
|
||||
func (s LocalCacheTermsOfServiceStore) GetLatest(allowFromCache bool) (*model.TermsOfService, error) {
|
||||
if allowFromCache {
|
||||
if l, err := s.rootStore.termsOfServiceCache.Len(); err == nil && l != 0 {
|
||||
var cacheItem *model.TermsOfService
|
||||
if err := s.rootStore.doStandardReadCache(s.rootStore.termsOfServiceCache, LatestKey, &cacheItem); err == nil {
|
||||
return cacheItem, nil
|
||||
}
|
||||
var cacheItem *model.TermsOfService
|
||||
if err := s.rootStore.doStandardReadCache(s.rootStore.termsOfServiceCache, LatestKey, &cacheItem); err == nil {
|
||||
return cacheItem, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user