Class: DNSTraverse::DecodedQueryCache

Inherits:
Object
  • Object
show all
Defined in:
lib/dnstraverse/decoded_query_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ DecodedQueryCache

Returns a new instance of DecodedQueryCache.



25
26
27
28
29
30
# File 'lib/dnstraverse/decoded_query_cache.rb', line 25

def initialize(args)
  @resolver = args[:resolver] || raise("Must pass resolver")
  @cache = Hash.new
  @requests = 0
  @cache_hits = 0
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



23
24
25
# File 'lib/dnstraverse/decoded_query_cache.rb', line 23

def cache
  @cache
end

#cache_hitsObject (readonly)

Returns the value of attribute cache_hits.



23
24
25
# File 'lib/dnstraverse/decoded_query_cache.rb', line 23

def cache_hits
  @cache_hits
end

#requestsObject (readonly)

Returns the value of attribute requests.



23
24
25
# File 'lib/dnstraverse/decoded_query_cache.rb', line 23

def requests
  @requests
end

#resolverObject (readonly)

Returns the value of attribute resolver.



23
24
25
# File 'lib/dnstraverse/decoded_query_cache.rb', line 23

def resolver
  @resolver
end

Instance Method Details

#query(args) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dnstraverse/decoded_query_cache.rb', line 32

def query(args)
  qname = args[:qname] || raise("Must pass qname")
  qclass = args[:qclass] || raise("Must pass qclass")
  qtype = args[:qtype] || raise("Must pass qtype")
  ip = args[:ip] || raise("Must pass ip")
  bailiwick = args[:bailiwick] # could be nil
  key = "key:dqc:#{ip}:#{qname}:#{qclass}:#{qtype}:#{bailiwick}"
  Log.debug { "Decoded Query Cache query #{key}" }
  if @cache.has_key?(key) then
    Log.debug { "Decoded Query Cache hit: #{key}" }
    @cache_hits+= 1
    return @cache[key]
  end
  newargs = args.merge( { :resolver => @resolver } )
  @cache[key] = DNSTraverse::DecodedQuery.new(newargs)
  Log.debug { "Decoded Query Cache store: #{key}" }
  return @cache[key]
end