Module: SolidCache::Store::Connections

Included in:
SolidCache::Store
Defined in:
lib/solid_cache/store/connections.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#shard_optionsObject (readonly)

Returns the value of attribute shard_options.



6
7
8
# File 'lib/solid_cache/store/connections.rb', line 6

def shard_options
  @shard_options
end

Instance Method Details

#connection_namesObject



53
54
55
# File 'lib/solid_cache/store/connections.rb', line 53

def connection_names
  connections.names
end

#connectionsObject



57
58
59
# File 'lib/solid_cache/store/connections.rb', line 57

def connections
  @connections ||= SolidCache::Connections.from_config(@shard_options)
end

#group_by_connection(keys) ⇒ Object



49
50
51
# File 'lib/solid_cache/store/connections.rb', line 49

def group_by_connection(keys)
  connections.assign(keys)
end

#initialize(options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/solid_cache/store/connections.rb', line 8

def initialize(options = {})
  super(options)
  if options[:clusters].present?
    if options[:clusters].size > 1
      raise ArgumentError, "Multiple clusters are no longer supported"
    else
      ActiveSupport.deprecator.warn(":clusters is deprecated, use :shards instead.")
    end
    @shard_options = options.fetch(:clusters).first[:shards]
  elsif options[:cluster].present?
    ActiveSupport.deprecator.warn(":cluster is deprecated, use :shards instead.")
    @shard_options = options.fetch(:cluster, {})[:shards]
  else
    @shard_options = options.fetch(:shards, nil)
  end

  if [ Array, NilClass ].none? { |klass| @shard_options.is_a? klass }
    raise ArgumentError, "`shards` is a `#{@shard_options.class.name}`, it should be Array or nil"
  end
end

#with_connection(name, async: false, &block) ⇒ Object



43
44
45
46
47
# File 'lib/solid_cache/store/connections.rb', line 43

def with_connection(name, async: false, &block)
  connections.with(name) do
    execute(async, &block)
  end
end

#with_connection_for(key, async: false, &block) ⇒ Object



37
38
39
40
41
# File 'lib/solid_cache/store/connections.rb', line 37

def with_connection_for(key, async: false, &block)
  connections.with_connection_for(key) do
    execute(async, &block)
  end
end

#with_each_connection(async: false, &block) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/solid_cache/store/connections.rb', line 29

def with_each_connection(async: false, &block)
  return enum_for(:with_each_connection) unless block_given?

  connections.with_each do
    execute(async, &block)
  end
end