Move cache setup to config/application.rb

Before this change we were trying to configure Rails.cache in an
initializer. It seems that by the time the initializers are loaded,
Rails.cache is already instantiated, so changing the settings does not
achieve anything anymore. This was causing Rails to default to a file
storage cache instead of the Redis cache, which in turn broke `rake
cache:clear`.
This commit is contained in:
Jacob Vosmaer 2014-08-29 11:38:21 +02:00
parent d4180875cb
commit 185e7681d2
2 changed files with 19 additions and 20 deletions

View file

@ -73,5 +73,24 @@ module Gitlab
resource '/api/*', headers: :any, methods: [:get, :post, :options, :put, :delete]
end
end
# Use Redis caching across all environments
redis_config_file = Rails.root.join('config', 'resque.yml')
redis_url_string = if File.exists?(redis_config_file)
YAML.load_file(redis_config_file)[Rails.env]
else
"redis://localhost:6379"
end
# Redis::Store does not handle Unix sockets well, so let's do it for them
redis_config_hash = Redis::Store::Factory.extract_host_options_from_uri(redis_url_string)
redis_uri = URI.parse(redis_url_string)
if redis_uri.scheme == 'unix'
redis_config_hash[:path] = redis_uri.path
end
redis_config_hash[:namespace] = 'cache:gitlab'
config.cache_store = :redis_store, redis_config_hash
end
end

View file

@ -1,20 +0,0 @@
Gitlab::Application.configure do
redis_config_file = Rails.root.join('config', 'resque.yml')
redis_url_string = if File.exists?(redis_config_file)
YAML.load_file(redis_config_file)[Rails.env]
else
"redis://localhost:6379"
end
# Redis::Store does not handle Unix sockets well, so let's do it for them
redis_config_hash = Redis::Store::Factory.extract_host_options_from_uri(redis_url_string)
redis_uri = URI.parse(redis_url_string)
if redis_uri.scheme == 'unix'
redis_config_hash[:path] = redis_uri.path
end
redis_config_hash[:namespace] = 'cache:gitlab'
config.cache_store = :redis_store, redis_config_hash
end