Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Set up cache store early in application.rb

Oliver Günther99ce4f9ad2a5
diff --git a/config/application.rb b/config/application.rb
index 353a1d4ed72..057159940f2 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -58,6 +58,9 @@ module OpenProject
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
+ # Set up the cache store based on our configuration
+ config.cache_store = OpenProject::Configuration.cache_store_configuration
+
# Set up STDOUT logging if requested
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
diff --git a/config/initializers/cache_store.rb b/config/initializers/cache_store.rb
deleted file mode 100644
index c57316fcee9..00000000000
--- a/config/initializers/cache_store.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2022 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-# Be sure to restart your server when you modify this file.
-OpenProject::Application.configure do
- OpenProject::Configuration.configure_cache(config)
-end
diff --git a/lib_static/open_project/configuration.rb b/lib_static/open_project/configuration.rb
index bfa49abc55e..590f2809648 100644
--- a/lib_static/open_project/configuration.rb
+++ b/lib_static/open_project/configuration.rb
@@ -44,7 +44,7 @@ module OpenProject
Settings::Definition[name].value = value
end
- def configure_cache(application_config)
+ def cache_store_configuration
# rails defaults to :file_store, use :mem_cache_store when :memcache is configured in configuration.yml
# Also use :mem_cache_store for when :dalli_store is configured
cache_store = self['rails_cache_store'].try(:to_sym)
@@ -63,7 +63,7 @@ module OpenProject
parameters = cache_store_parameters
cache_config << parameters unless parameters.empty?
- application_config.cache_store = cache_config
+ cache_config
end
def cache_store_parameters
diff --git a/spec/lib/open_project/configuration_spec.rb b/spec/lib/open_project/configuration_spec.rb
index 18f075019a5..9d0fa0a9846 100644
--- a/spec/lib/open_project/configuration_spec.rb
+++ b/spec/lib/open_project/configuration_spec.rb
@@ -55,38 +55,14 @@ describe OpenProject::Configuration, :settings_reset do
end
end
- describe '.configure_cache' do
- let(:application_config) do
- Rails::Application::Configuration.new Rails.root
- end
-
- context 'with cache store already set' do
- before do
- application_config.cache_store = 'foo'
- end
-
- context 'with additional cache store configuration' do
- before do
- described_class['rails_cache_store'] = 'bar'
- end
-
- it 'changes the cache store' do
- described_class.send(:configure_cache, application_config)
- expect(application_config.cache_store).to eq([:bar])
- end
- end
- end
+ describe '.cache_store_configuration' do
+ subject { described_class.cache_store_configuration }
context 'without cache store already set' do
- before do
- application_config.cache_store = nil
- described_class.send(:configure_cache, application_config)
- end
context 'with additional cache store configuration', with_config: { 'rails_cache_store' => 'bar' } do
it 'changes the cache store' do
- described_class.send(:configure_cache, application_config)
- expect(application_config.cache_store).to eq([:bar])
+ expect(subject).to eq([:bar])
end
end
@@ -96,8 +72,7 @@ describe OpenProject::Configuration, :settings_reset do
end
it 'defaults the cache store to :file_store' do
- described_class.send(:configure_cache, application_config)
- expect(application_config.cache_store.first).to eq(:file_store)
+ expect(subject.first).to eq(:file_store)
end
end
end