[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
145
store/storetest/mocks/Cache.go
Обычный файл
145
store/storetest/mocks/Cache.go
Обычный файл
@@ -0,0 +1,145 @@
|
||||
// Code generated by mockery v1.0.0. DO NOT EDIT.
|
||||
|
||||
// Regenerate this file using `make store-mocks`.
|
||||
|
||||
package mocks
|
||||
|
||||
import (
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
time "time"
|
||||
)
|
||||
|
||||
// Cache is an autogenerated mock type for the Cache type
|
||||
type Cache struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
// Add provides a mock function with given fields: key, value
|
||||
func (_m *Cache) Add(key interface{}, value interface{}) {
|
||||
_m.Called(key, value)
|
||||
}
|
||||
|
||||
// AddWithDefaultExpires provides a mock function with given fields: key, value
|
||||
func (_m *Cache) AddWithDefaultExpires(key interface{}, value interface{}) {
|
||||
_m.Called(key, value)
|
||||
}
|
||||
|
||||
// AddWithExpiresInSecs provides a mock function with given fields: key, value, expireAtSecs
|
||||
func (_m *Cache) AddWithExpiresInSecs(key interface{}, value interface{}, expireAtSecs int64) {
|
||||
_m.Called(key, value, expireAtSecs)
|
||||
}
|
||||
|
||||
// Get provides a mock function with given fields: key
|
||||
func (_m *Cache) Get(key interface{}) (interface{}, bool) {
|
||||
ret := _m.Called(key)
|
||||
|
||||
var r0 interface{}
|
||||
if rf, ok := ret.Get(0).(func(interface{}) interface{}); ok {
|
||||
r0 = rf(key)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(interface{})
|
||||
}
|
||||
}
|
||||
|
||||
var r1 bool
|
||||
if rf, ok := ret.Get(1).(func(interface{}) bool); ok {
|
||||
r1 = rf(key)
|
||||
} else {
|
||||
r1 = ret.Get(1).(bool)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetInvalidateClusterEvent provides a mock function with given fields:
|
||||
func (_m *Cache) GetInvalidateClusterEvent() string {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 string
|
||||
if rf, ok := ret.Get(0).(func() string); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
r0 = ret.Get(0).(string)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// GetOrAdd provides a mock function with given fields: key, value, ttl
|
||||
func (_m *Cache) GetOrAdd(key interface{}, value interface{}, ttl time.Duration) (interface{}, bool) {
|
||||
ret := _m.Called(key, value, ttl)
|
||||
|
||||
var r0 interface{}
|
||||
if rf, ok := ret.Get(0).(func(interface{}, interface{}, time.Duration) interface{}); ok {
|
||||
r0 = rf(key, value, ttl)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(interface{})
|
||||
}
|
||||
}
|
||||
|
||||
var r1 bool
|
||||
if rf, ok := ret.Get(1).(func(interface{}, interface{}, time.Duration) bool); ok {
|
||||
r1 = rf(key, value, ttl)
|
||||
} else {
|
||||
r1 = ret.Get(1).(bool)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// Keys provides a mock function with given fields:
|
||||
func (_m *Cache) Keys() []interface{} {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 []interface{}
|
||||
if rf, ok := ret.Get(0).(func() []interface{}); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]interface{})
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Len provides a mock function with given fields:
|
||||
func (_m *Cache) Len() int {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 int
|
||||
if rf, ok := ret.Get(0).(func() int); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
r0 = ret.Get(0).(int)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Name provides a mock function with given fields:
|
||||
func (_m *Cache) Name() string {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 string
|
||||
if rf, ok := ret.Get(0).(func() string); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
r0 = ret.Get(0).(string)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Purge provides a mock function with given fields:
|
||||
func (_m *Cache) Purge() {
|
||||
_m.Called()
|
||||
}
|
||||
|
||||
// Remove provides a mock function with given fields: key
|
||||
func (_m *Cache) Remove(key interface{}) {
|
||||
_m.Called(key)
|
||||
}
|
||||
57
store/storetest/mocks/CacheProvider.go
Обычный файл
57
store/storetest/mocks/CacheProvider.go
Обычный файл
@@ -0,0 +1,57 @@
|
||||
// Code generated by mockery v1.0.0. DO NOT EDIT.
|
||||
|
||||
// Regenerate this file using `make store-mocks`.
|
||||
|
||||
package mocks
|
||||
|
||||
import (
|
||||
cache "github.com/mattermost/mattermost-server/v5/services/cache"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// CacheProvider is an autogenerated mock type for the CacheProvider type
|
||||
type CacheProvider struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
// NewCache provides a mock function with given fields: size
|
||||
func (_m *CacheProvider) NewCache(size int) cache.Cache {
|
||||
ret := _m.Called(size)
|
||||
|
||||
var r0 cache.Cache
|
||||
if rf, ok := ret.Get(0).(func(int) cache.Cache); ok {
|
||||
r0 = rf(size)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(cache.Cache)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Connect provides a mock function with given fields:
|
||||
func (_m *CacheProvider) Connect() {
|
||||
_m.Called()
|
||||
}
|
||||
|
||||
// Close provides a mock function with given fields:
|
||||
func (_m *CacheProvider) Close() {
|
||||
_m.Called()
|
||||
}
|
||||
|
||||
// NewCacheWithParams provides a mock function with given fields: size, name, defaultExpiry, invalidateClusterEvent
|
||||
func (_m *CacheProvider) NewCacheWithParams(size int, name string, defaultExpiry int64, invalidateClusterEvent string) cache.Cache {
|
||||
ret := _m.Called(size, name, defaultExpiry, invalidateClusterEvent)
|
||||
|
||||
var r0 cache.Cache
|
||||
if rf, ok := ret.Get(0).(func(int, string, int64, string) cache.Cache); ok {
|
||||
r0 = rf(size, name, defaultExpiry, invalidateClusterEvent)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(cache.Cache)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
@@ -4,10 +4,9 @@
|
||||
package storetest
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/mock"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// Store can be used to provide mock stores for testing.
|
||||
|
||||
Ссылка в новой задаче
Block a user