Class: Roma::DNSCache

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/roma/dns_cache.rb

Instance Method Summary collapse

Constructor Details

#initializeDNSCache

Returns a new instance of DNSCache.



7
8
9
10
11
12
13
# File 'lib/roma/dns_cache.rb', line 7

def initialize
  @@addrs = {}
  @@enabled_caching = false
  if Config.const_defined?(:DNS_CACHING)
    @@enabled_caching = Config::DNS_CACHING
  end
end

Instance Method Details

#disable_dns_cacheObject



25
26
27
28
# File 'lib/roma/dns_cache.rb', line 25

def disable_dns_cache
  @@enabled_caching = false
  @@addrs.clear
end

#enable_dns_cacheObject



30
31
32
# File 'lib/roma/dns_cache.rb', line 30

def enable_dns_cache
  @@enabled_caching = true
end

#get_statObject



34
35
36
37
38
# File 'lib/roma/dns_cache.rb', line 34

def get_stat
  ret = {}
  ret["dns_caching"] = @@enabled_caching
  ret
end

#resolve_name(host) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/roma/dns_cache.rb', line 15

def resolve_name(host)
  return host unless @@enabled_caching

  unless @@addrs.include?(host)
    res = TCPSocket.gethostbyname(host)
    @@addrs[host] = res[3]
  end
  @@addrs[host]
end