Class: DohDb::CacheConnector

Inherits:
Object
  • Object
show all
Defined in:
lib/doh/mysql/cache_connector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = nil, username = nil, password = nil, database = nil, row_builder = nil) ⇒ CacheConnector

Returns a new instance of CacheConnector.



10
11
12
13
14
15
16
17
18
# File 'lib/doh/mysql/cache_connector.rb', line 10

def initialize(host = nil, username = nil, password = nil, database = nil, row_builder = nil)
  @host = host
  @username = username
  @password = password
  @database = database
  @timeout = 1800
  @port = nil
  @row_builder = row_builder || TypedRowBuilder.new
end

Instance Attribute Details

#databaseObject

Returns the value of attribute database.



8
9
10
# File 'lib/doh/mysql/cache_connector.rb', line 8

def database
  @database
end

#hostObject

Returns the value of attribute host.



8
9
10
# File 'lib/doh/mysql/cache_connector.rb', line 8

def host
  @host
end

#passwordObject

Returns the value of attribute password.



8
9
10
# File 'lib/doh/mysql/cache_connector.rb', line 8

def password
  @password
end

#portObject

Returns the value of attribute port.



8
9
10
# File 'lib/doh/mysql/cache_connector.rb', line 8

def port
  @port
end

#row_builderObject

Returns the value of attribute row_builder.



8
9
10
# File 'lib/doh/mysql/cache_connector.rb', line 8

def row_builder
  @row_builder
end

#timeoutObject

Returns the value of attribute timeout.



8
9
10
# File 'lib/doh/mysql/cache_connector.rb', line 8

def timeout
  @timeout
end

#usernameObject

Returns the value of attribute username.



8
9
10
# File 'lib/doh/mysql/cache_connector.rb', line 8

def username
  @username
end

Instance Method Details

#request_handle(database = nil) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/doh/mysql/cache_connector.rb', line 20

def request_handle(database = nil)
  if @handle
    close_handle("handle was unused for too long") if passed_timeout?
    @handle = nil if @handle && @handle.closed?
  end
  @last_used = Time.now
  @handle ||= get_new_handle(database)
end

#resetObject



29
30
31
# File 'lib/doh/mysql/cache_connector.rb', line 29

def reset
  close_handle("reset")
end