a little more flexibility with cache_store config refs #10114

no user visible change

test plan:
 * smoke test with and without caching configured

Change-Id: Ia21a996988021d647e56f85cd8ce818b64001681
Reviewed-on: https://gerrit.instructure.com/13248
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
This commit is contained in:
Cody Cutrer 2012-08-27 12:22:23 -06:00
parent d868f35c13
commit 72f298bf46
2 changed files with 14 additions and 10 deletions

View File

@ -64,8 +64,8 @@ class Setting < ActiveRecord::Base
s.destroy if s
end
def self.config_key(config_name, with_current_rails_env=true)
"yaml_config_#{config_name}_#{Rails.env}_#{with_current_rails_env}"
def self.config_key(config_name, with_rails_env=:current)
"yaml_config_#{config_name}_#{with_rails_env == :current ? Rails.env : with_rails_env}"
end
def self.set_config(config_name, value)
@ -73,8 +73,8 @@ class Setting < ActiveRecord::Base
@@cache[config_key(config_name)] = value
end
def self.from_config(config_name, with_current_rails_env=true)
key = config_key(config_name, with_current_rails_env)
def self.from_config(config_name, with_rails_env=:current)
key = config_key(config_name, with_rails_env)
return @@cache[key] if @@cache[key] # if the config wasn't found it'll try again
@ -82,7 +82,7 @@ class Setting < ActiveRecord::Base
path = File.join(Rails.root, 'config', "#{config_name}.yml")
if File.exists?(path)
config = YAML.load_file(path).with_indifferent_access
config = config[Rails.env] if with_current_rails_env
config = config[with_rails_env == :current ? Rails.env : with_rails_env] if with_rails_env
end
@@cache[key] = config
end

View File

@ -60,15 +60,15 @@ module Canvas
end
end
def self.cache_store_config
def self.cache_store_config(rails_env = :current, nil_is_nil = false)
cache_store_config = {
'cache_store' => 'mem_cache_store',
}.merge(Setting.from_config('cache_store') || {})
}.merge(Setting.from_config('cache_store', rails_env) || {})
config = nil
case cache_store_config.delete('cache_store')
when 'mem_cache_store'
cache_store_config['namespace'] ||= cache_store_config['key']
servers = cache_store_config['servers'] || (Setting.from_config('memcache'))
servers = cache_store_config['servers'] || (Setting.from_config('memcache', rails_env))
if servers
config = :mem_cache_store, servers, cache_store_config
end
@ -79,12 +79,16 @@ module Canvas
#
# the only options currently supported in redis-cache are the list of
# servers, not key prefix or database names.
cache_store_config = (Setting.from_config('redis') || {}).merge(cache_store_config)
cache_store_config = (Setting.from_config('redis', rails_env) || {}).merge(cache_store_config)
cache_store_config['key_prefix'] ||= cache_store_config['key']
servers = cache_store_config['servers']
config = :redis_store, servers
when 'memory_store'
config = :memory_store
when 'nil_store'
config = :nil_store
end
unless config
if !config && !nil_is_nil
config = :nil_store
end
config