Class: DohDb::CacheConnector

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ CacheConnector

Returns a new instance of CacheConnector.



9
10
11
12
13
# File 'lib/dohmysql/cache_connector.rb', line 9

def initialize(config)
  @config = config
  @config[:timeout] ||= 1800
  @handle = nil
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



7
8
9
# File 'lib/dohmysql/cache_connector.rb', line 7

def config
  @config
end

Instance Method Details

#request_handle(database = nil) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/dohmysql/cache_connector.rb', line 15

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



24
25
26
# File 'lib/dohmysql/cache_connector.rb', line 24

def reset
  close_handle('reset was called')
end