Class: ActiveSupport::Cache::MemcacheConnectionPool

Inherits:
Object
  • Object
show all
Defined in:
lib/active_support/cache/memcache_connection_pool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ MemcacheConnectionPool

Returns a new instance of MemcacheConnectionPool.



6
7
8
# File 'lib/active_support/cache/memcache_connection_pool.rb', line 6

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/active_support/cache/memcache_connection_pool.rb', line 4

def options
  @options
end

Instance Method Details

#async_connection_poolObject



74
75
76
77
78
79
80
# File 'lib/active_support/cache/memcache_connection_pool.rb', line 74

def async_connection_pool
  @async_connection_pool ||=
    begin
      spec = ActiveRecord::Base::ConnectionSpecification.new @options.merge(:async => true), (@options[:async_adapter_method] || @options[:adapter_method])
      WithConnection::ConnectionPool.new @options[:name], spec
    end
end

#connectionObject



99
100
101
# File 'lib/active_support/cache/memcache_connection_pool.rb', line 99

def connection
  connection_pool.connection
end

#connection_poolObject



82
83
84
# File 'lib/active_support/cache/memcache_connection_pool.rb', line 82

def connection_pool
  EM.reactor_running? ? async_connection_pool : sync_connection_pool
end

#decrement(name, amount = 1, options = nil) ⇒ Object



52
53
54
55
56
# File 'lib/active_support/cache/memcache_connection_pool.rb', line 52

def decrement(name, amount = 1, options=nil)
  with_connection do
    options ? connection.decrement(name, amount, options) : connection.decrement(name, amount)
  end
end

#delete(name, options = nil) ⇒ Object



34
35
36
37
38
# File 'lib/active_support/cache/memcache_connection_pool.rb', line 34

def delete(name, options=nil)
  with_connection do
    options ? connection.delete(name, options) : connection.delete(name)
  end
end

#exist?(name, options = nil) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/active_support/cache/memcache_connection_pool.rb', line 28

def exist?(name, options=nil)
  with_connection do
    options ? connection.exist?(name, options) : connection.exist?(name)
  end
end

#fetch(name, options = nil) ⇒ Object



10
11
12
13
14
# File 'lib/active_support/cache/memcache_connection_pool.rb', line 10

def fetch(name, options=nil)
  with_connection do
    options ? connection.fetch(name, options) : connection.fetch(name)
  end
end

#increment(name, amount = 1, options = nil) ⇒ Object



46
47
48
49
50
# File 'lib/active_support/cache/memcache_connection_pool.rb', line 46

def increment(name, amount = 1, options=nil)
  with_connection do
    options ? connection.increment(name, amount, options) : connection.increment(name, amount)
  end
end

#read(name, options = nil) ⇒ Object



16
17
18
19
20
# File 'lib/active_support/cache/memcache_connection_pool.rb', line 16

def read(name, options=nil)
  with_connection do
    options ? connection.read(name, options) : connection.read(name)
  end
end

#read_multi(*names) ⇒ Object



40
41
42
43
44
# File 'lib/active_support/cache/memcache_connection_pool.rb', line 40

def read_multi(*names)
  with_connection do
    connection.read_multi *names
  end
end

#reset(options = nil) ⇒ Object Also known as: clear



58
59
60
61
62
# File 'lib/active_support/cache/memcache_connection_pool.rb', line 58

def reset(options=nil)
  with_connection do
    options ? connection.reset(options) : connection.reset
  end
end

#sync_connection_poolObject



66
67
68
69
70
71
72
# File 'lib/active_support/cache/memcache_connection_pool.rb', line 66

def sync_connection_pool
  @sync_connection_pool ||=
    begin
      spec = ActiveRecord::Base::ConnectionSpecification.new @options.dup, @options[:adapter_method]
      WithConnection::ConnectionPool.new @options[:name], spec
    end
end

#with_connection(&block) ⇒ Object



95
96
97
# File 'lib/active_support/cache/memcache_connection_pool.rb', line 95

def with_connection(&block)
  connection_pool.with_connection(&block)
end

#write(name, value, options = nil) ⇒ Object



22
23
24
25
26
# File 'lib/active_support/cache/memcache_connection_pool.rb', line 22

def write(name, value, options=nil)
  with_connection do
    options ? connection.write(name, value, options) : connection.write(name, value)
  end
end