diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e379dd1b0ca11686489ecec64abc68a4cadd0e4..fc53c1b51791e2664b2e13dad7e7d5dc4e362721 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +### Deprecation notices + +In a future version (likely the next), the in-memory cache support will be removed. Instead, please use the Redis +caching that is now supported properly by this release, or disable caching if not applicable for your deployment. + +### Changed + +* Support the Redis config at the root level of the config, promoting it to a proper feature. + ## [1.2.7] - April 19th, 2021 ### Security advisories diff --git a/common/config/conf_main.go b/common/config/conf_main.go index 3d255c56eadaace116842afca7bc54e8461b057d..e061590f4fb2b8dd9db2ed686fef85511c923517 100644 --- a/common/config/conf_main.go +++ b/common/config/conf_main.go @@ -15,6 +15,7 @@ type MainRepoConfig struct { Federation FederationConfig `yaml:"federation"` Plugins []PluginConfig `yaml:"plugins,flow"` Sentry SentryConfig `yaml:"sentry"` + Redis RedisConfig `yaml:"redis"` } func NewDefaultMainConfig() MainRepoConfig { @@ -136,5 +137,9 @@ func NewDefaultMainConfig() MainRepoConfig { Environment: "", Debug: false, }, + Redis: RedisConfig{ + Enabled: false, + Shards: []RedisShardConfig{}, + }, } } diff --git a/common/config/models_domain.go b/common/config/models_domain.go index fbc49152229fc6294d0d9b5537a7757e2d5e7f6b..14ef0f30eb5c0aeeb8dbc4f991f114bd6e40d801 100644 --- a/common/config/models_domain.go +++ b/common/config/models_domain.go @@ -111,16 +111,6 @@ type IPFSDaemonConfig struct { RepoPath string `yaml:"repoPath"` } -type RedisConfig struct { - Enabled bool `yaml:"enabled"` - Shards []RedisShardConfig `yaml:"shards,flow"` -} - -type RedisShardConfig struct { - Name string `yaml:"name"` - Address string `yaml:"addr"` -} - type AccessTokenConfig struct { MaxCacheTimeSeconds int `yaml:"maxCacheTimeSeconds"` UseAppservices bool `yaml:"useLocalAppserviceConfig"` diff --git a/common/config/models_main.go b/common/config/models_main.go index a331754ba4dbf50271be95ab6677dfbae8820d0a..02bc8ab7257cca09f7e94644bf5e854edfb9905f 100644 --- a/common/config/models_main.go +++ b/common/config/models_main.go @@ -88,3 +88,13 @@ type SentryConfig struct { Environment string `yaml:"environment"` Debug bool `yaml:"debug"` } + +type RedisConfig struct { + Enabled bool `yaml:"enabled"` + Shards []RedisShardConfig `yaml:"shards,flow"` +} + +type RedisShardConfig struct { + Name string `yaml:"name"` + Address string `yaml:"addr"` +} \ No newline at end of file diff --git a/internal_cache/instance.go b/internal_cache/instance.go index dabf916f488ddfbe175ab4ba86529b0d6e2fad94..22bcebb6ce0fde5b84c9e97bbd13588db6d301b6 100644 --- a/internal_cache/instance.go +++ b/internal_cache/instance.go @@ -1,6 +1,7 @@ package internal_cache import ( + "github.com/getsentry/sentry-go" "sync" "github.com/sirupsen/logrus" @@ -16,14 +17,27 @@ func Get() ContentCache { } lock.Do(func() { - if config.Get().Features.Redis.Enabled { + if config.Get().Redis.Enabled { logrus.Info("Setting up Redis cache") + instance = NewRedisCache() + } else if config.Get().Features.Redis.Enabled { + logrus.Info("Setting up Redis cache") + + warnMsg := "Your configuration uses a legacy approach for enabling Redis support. Please move this to the root config or visit #media-repo:t2bot.io for assistance." + logrus.Warn(warnMsg) + sentry.CaptureMessage(warnMsg) + instance = NewRedisCache() } else if !config.Get().Downloads.Cache.Enabled { logrus.Warn("Cache is disabled - setting up a dummy instance") instance = NewNoopCache() } else { logrus.Info("Setting up in-memory cache") + + warnMsg := "The built-in cache mechanism is being removed in a future version. Please set up Redis as a cache mechanism." + logrus.Warn(warnMsg) + sentry.CaptureMessage(warnMsg) + instance = NewMemoryCache() } })