From 72f298bf46bf7a8c14fd4b063d2627ce172d747b Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Mon, 27 Aug 2012 12:22:23 -0600 Subject: [PATCH] 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 Reviewed-by: Brian Palmer --- app/models/setting.rb | 10 +++++----- lib/canvas.rb | 14 +++++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/models/setting.rb b/app/models/setting.rb index f29106cb51a..b5f4ffbdd90 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -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 diff --git a/lib/canvas.rb b/lib/canvas.rb index 3a0192a34c4..ce58163d9a7 100644 --- a/lib/canvas.rb +++ b/lib/canvas.rb @@ -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