diff --git a/app/models/miq_server/worker_management/monitor.rb b/app/models/miq_server/worker_management/monitor.rb index 739827b9cbe..3f1b7df4eb2 100644 --- a/app/models/miq_server/worker_management/monitor.rb +++ b/app/models/miq_server/worker_management/monitor.rb @@ -166,8 +166,7 @@ def sync_monitor end def key_store - require 'dalli' - @key_store ||= Dalli::Client.new(MiqMemcached.server_address, :namespace => "server_monitor") + @key_store ||= MiqMemcached.client(:namespace => "server_monitor") end def notify_workers_of_config_change(last_sync) diff --git a/app/models/miq_worker/runner.rb b/app/models/miq_worker/runner.rb index 7de832b024f..459e5b0c33e 100644 --- a/app/models/miq_worker/runner.rb +++ b/app/models/miq_worker/runner.rb @@ -319,8 +319,7 @@ def config_out_of_date? end def key_store - require 'dalli' - @key_store ||= Dalli::Client.new(MiqMemcached.server_address, :namespace => "server_monitor") + @key_store ||= MiqMemcached.client(:namespace => "server_monitor") end def server_last_change(key) diff --git a/lib/manageiq/session/mem_cache_store_adapter.rb b/lib/manageiq/session/mem_cache_store_adapter.rb index d0b6b326036..237cb64764c 100644 --- a/lib/manageiq/session/mem_cache_store_adapter.rb +++ b/lib/manageiq/session/mem_cache_store_adapter.rb @@ -9,7 +9,7 @@ def type def session_options opts = super - cache = Dalli::Client.new(MiqMemcached.server_address, :namespace => "MIQ:VMDB", :value_max_bytes => 10.megabytes) + cache = MiqMemcached.client(:namespace => "MIQ:VMDB", :value_max_bytes => 10.megabytes) opts.merge( :cache => cache, :expire_after => 24.hours, diff --git a/lib/miq_memcached.rb b/lib/miq_memcached.rb index ab64cb82010..3e2c1eb6249 100644 --- a/lib/miq_memcached.rb +++ b/lib/miq_memcached.rb @@ -10,6 +10,13 @@ def self.server_address end end + # @param options options passed to the memcached client + # e.g.: :namespace => namespace + def self.client(options) + require 'dalli' + Dalli::Client.new(MiqMemcached.server_address, options) + end + class Error < RuntimeError; end class ControlError < Error; end diff --git a/lib/token_store.rb b/lib/token_store.rb index 9b3f9cb05bc..9927116880b 100644 --- a/lib/token_store.rb +++ b/lib/token_store.rb @@ -1,17 +1,20 @@ class TokenStore @token_caches = {} # Hash of Memory/Dalli Store Caches, Keyed by namespace + # only used by TokenManager.token_store + # @return a token store for users def self.acquire(namespace, token_ttl) @token_caches[namespace] ||= begin + options = cache_store_options(namespace, token_ttl) case ::Settings.server.session_store when "sql" - SqlStore.new(cache_store_options(namespace, token_ttl)) + SqlStore.new(options) when "memory" require 'active_support/cache/memory_store' - ActiveSupport::Cache::MemoryStore.new(cache_store_options(namespace, token_ttl)) + ActiveSupport::Cache::MemoryStore.new(options) when "cache" require 'active_support/cache/dalli_store' - ActiveSupport::Cache::DalliStore.new(MiqMemcached.server_address, cache_store_options(namespace, token_ttl)) + ActiveSupport::Cache::DalliStore.new(MiqMemcached.server_address, options) else raise "unsupported session store type: #{::Settings.server.session_store}" end