Class: Roma::DNSCache
- Inherits:
-
Object
- Object
- Roma::DNSCache
- Includes:
- Singleton
- Defined in:
- lib/roma/dns_cache.rb
Instance Method Summary collapse
- #disable_dns_cache ⇒ Object
- #enable_dns_cache ⇒ Object
- #get_stat ⇒ Object
-
#initialize ⇒ DNSCache
constructor
A new instance of DNSCache.
- #resolve_name(host) ⇒ Object
Constructor Details
#initialize ⇒ DNSCache
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_cache ⇒ Object
25 26 27 28 |
# File 'lib/roma/dns_cache.rb', line 25 def disable_dns_cache @@enabled_caching = false @@addrs.clear end |
#enable_dns_cache ⇒ Object
30 31 32 |
# File 'lib/roma/dns_cache.rb', line 30 def enable_dns_cache @@enabled_caching = true end |
#get_stat ⇒ Object
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 |