[MM 19840] Create a Cache Interface abstraction to support multiple cache backends (#13384)
* Refactor to use structured logging * Properly formatted with gofmt * created interface Cache, but construction of cache is still coupled. * Implementing cache factories to build caches * Simple redis implementation without error handling. Keys and values by default are string * refactor NewLocalCacheLayer to inject cache factory * Removed redis impl to focus on cache abstraction * CacheFactory injected on sqlsupplier and saved in Store struct * remove useless private method * replace concrete declaration of lru cache to cache abstraction * discard spaces * Renamed factory to provider because concrete implementations of factories may hold an state (such as a redis client for example) * refactor to include all caches in the same package cache and subpackages * method close cache. This method will be used for concrete implementations that need to release resources (close a connection, etc) * closing cacheprovider and releasing resources while closing sql store * fixed merge conflict fail * gofmt files * remove unused property from post_store * naming refactor to avoid stutter. Added godocs on interface * Store doesnt know anything about the cache and provider. Cache provider will be built after loading config and injected in localCacheLayer * fixed broken test * cache provider initialized before RunOldAppInitialization which initializes the localcachelayer * move statusCache to server to initialize it with the new cache provider * update terms_service and channel_layer to have new cacheProvider * gofmt * Add Connect method to the cache provider * mock cacheprovider in user_layer_test Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com> Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
1909fd6607
Коммит
62b57143c8
@@ -18,8 +18,8 @@ import (
|
||||
"github.com/mattermost/mattermost-server/v5/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/services/cache/lru"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
"github.com/mattermost/mattermost-server/v5/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -274,9 +274,9 @@ type publicChannel struct {
|
||||
Purpose string `json:"purpose"`
|
||||
}
|
||||
|
||||
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 channelByNameCache = utils.NewLru(model.CHANNEL_CACHE_SIZE)
|
||||
var allChannelMembersForUserCache = lru.New(ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SIZE)
|
||||
var allChannelMembersNotifyPropsForChannelCache = lru.New(ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_SIZE)
|
||||
var channelByNameCache = lru.New(model.CHANNEL_CACHE_SIZE)
|
||||
|
||||
func (s SqlChannelStore) ClearCaches() {
|
||||
allChannelMembersForUserCache.Purge()
|
||||
|
||||
@@ -11,8 +11,9 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/services/cache"
|
||||
"github.com/mattermost/mattermost-server/v5/services/cache/lru"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
"github.com/mattermost/mattermost-server/v5/utils"
|
||||
)
|
||||
|
||||
type SqlFileInfoStore struct {
|
||||
@@ -25,7 +26,7 @@ const (
|
||||
FILE_INFO_CACHE_SEC = 1800 // 30 minutes
|
||||
)
|
||||
|
||||
var fileInfoCache *utils.Cache = utils.NewLru(FILE_INFO_CACHE_SIZE)
|
||||
var fileInfoCache cache.Cache = lru.New(FILE_INFO_CACHE_SIZE)
|
||||
|
||||
func (fs SqlFileInfoStore) ClearCaches() {
|
||||
fileInfoCache.Purge()
|
||||
|
||||
@@ -16,8 +16,9 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/services/cache"
|
||||
"github.com/mattermost/mattermost-server/v5/services/cache/lru"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
"github.com/mattermost/mattermost-server/v5/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -41,7 +42,7 @@ type SqlUserStore struct {
|
||||
usersQuery sq.SelectBuilder
|
||||
}
|
||||
|
||||
var profilesInChannelCache *utils.Cache = utils.NewLru(PROFILES_IN_CHANNEL_CACHE_SIZE)
|
||||
var profilesInChannelCache cache.Cache = lru.New(PROFILES_IN_CHANNEL_CACHE_SIZE)
|
||||
|
||||
func (us SqlUserStore) ClearCaches() {
|
||||
profilesInChannelCache.Purge()
|
||||
|
||||
Ссылка в новой задаче
Block a user