Skip to content

Commit

Permalink
Merge pull request ManageIQ#20663 from kbrock/memcache-client
Browse files Browse the repository at this point in the history
Memcache client
  • Loading branch information
Fryguy committed Oct 6, 2020
2 parents 684503d + 8b4af88 commit 4c1e528
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
3 changes: 1 addition & 2 deletions app/models/miq_server/worker_management/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions app/models/miq_worker/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/manageiq/session/mem_cache_store_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions lib/miq_memcached.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions lib/token_store.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 4c1e528

Please sign in to comment.