Class: DNSTraverse::DecodedQueryCache
- Inherits:
-
Object
- Object
- DNSTraverse::DecodedQueryCache
- Defined in:
- lib/dnstraverse/decoded_query_cache.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#cache_hits ⇒ Object
readonly
Returns the value of attribute cache_hits.
-
#requests ⇒ Object
readonly
Returns the value of attribute requests.
-
#resolver ⇒ Object
readonly
Returns the value of attribute resolver.
Instance Method Summary collapse
-
#initialize(args) ⇒ DecodedQueryCache
constructor
A new instance of DecodedQueryCache.
- #query(args) ⇒ Object
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
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
23 24 25 |
# File 'lib/dnstraverse/decoded_query_cache.rb', line 23 def cache @cache end |
#cache_hits ⇒ Object (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 |
#requests ⇒ Object (readonly)
Returns the value of attribute requests.
23 24 25 |
# File 'lib/dnstraverse/decoded_query_cache.rb', line 23 def requests @requests end |
#resolver ⇒ Object (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 |