Class: Dnsruby::Cache
- Inherits:
-
Object
- Object
- Dnsruby::Cache
- Defined in:
- lib/Dnsruby/Cache.rb
Overview
:nodoc: all
Defined Under Namespace
Class Method Summary collapse
Instance Method Summary collapse
- #add(message) ⇒ Object
- #cache ⇒ Object
- #clear ⇒ Object
-
#find(qname, qtype, qclass = Classes.IN) ⇒ Object
This method “fixes up” the response, so that the header and ttls are OK The resolver will still need to copy the flags and ID across from the query.
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
Constructor Details
#initialize ⇒ Cache
Returns a new instance of Cache.
15 16 17 18 |
# File 'lib/Dnsruby/Cache.rb', line 15 def initialize() @cache = Hash.new @mutex = Mutex.new end |
Class Method Details
Instance Method Details
#add(message) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/Dnsruby/Cache.rb', line 27 def add() q = .question[0] key = CacheKey.new(q.qname, q.qtype, q.qclass).to_s data = CacheData.new() @mutex.synchronize { if (@cache[key]) TheLog.debug("CACHE REPLACE : #{q.qname}, #{q.qtype}\n") else TheLog.debug("CACHE ADD : #{q.qname}, #{q.qtype}\n") end @cache[key] = data } end |
#cache ⇒ Object
19 20 21 |
# File 'lib/Dnsruby/Cache.rb', line 19 def cache @cache end |
#clear ⇒ Object
22 23 24 25 26 |
# File 'lib/Dnsruby/Cache.rb', line 22 def clear() @mutex.synchronize { @cache = Hash.new } end |
#find(qname, qtype, qclass = Classes.IN) ⇒ Object
This method “fixes up” the response, so that the header and ttls are OK The resolver will still need to copy the flags and ID across from the query
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/Dnsruby/Cache.rb', line 42 def find(qname, qtype, qclass = Classes.IN) # print "CACHE find : #{qname}, #{qtype}\n" qn = Name.create(qname) qn.absolute = true key = CacheKey.new(qn, qtype, qclass).to_s @mutex.synchronize { data = @cache[key] if (!data) # print "CACHE lookup failed\n" return nil end if (data.expiration <= Time.now.to_i) @cache.delete(key) TheLog.debug("CACHE lookup stale\n") return nil end m = data. TheLog.debug("CACHE found\n") return m } end |