Class: Dnsruby::Cache::CacheData
- Inherits:
-
Object
- Object
- Dnsruby::Cache::CacheData
- Defined in:
- lib/Dnsruby/Cache.rb
Instance Attribute Summary collapse
-
#expiration ⇒ Object
readonly
Returns the value of attribute expiration.
Instance Method Summary collapse
- #get_expiration(m) ⇒ Object
-
#initialize(*args) ⇒ CacheData
constructor
A new instance of CacheData.
- #message ⇒ Object
- #message=(m) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*args) ⇒ CacheData
123 124 125 126 127 |
# File 'lib/Dnsruby/Cache.rb', line 123 def initialize(*args) @expiration = 0 @time_stored = Time.now.to_i self.=(args[0]) end |
Instance Attribute Details
#expiration ⇒ Object (readonly)
Returns the value of attribute expiration.
89 90 91 |
# File 'lib/Dnsruby/Cache.rb', line 89 def expiration @expiration end |
Instance Method Details
#get_expiration(m) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/Dnsruby/Cache.rb', line 108 def get_expiration(m) # Find the minimum ttl of any of the rrsets min_ttl = 9999999 m.each_section {|section| section.rrsets.each {|rrset| if (rrset.ttl < min_ttl) min_ttl = rrset.ttl end } } if (min_ttl == 9999999) return 0 end return (Time.now.to_i + min_ttl) end |
#message ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/Dnsruby/Cache.rb', line 95 def m = Message.decode(.encode) m.cached = true # @TODO@ What do we do about answerfrom, answersize, etc.? m.header.aa = false # Anything else to do here? # Fix up TTLs!! offset = (Time.now - @time_stored).to_i m.each_resource {|rr| next if rr.type == Types.OPT rr.ttl = rr.ttl - offset } return m end |
#message=(m) ⇒ Object
90 91 92 93 94 |
# File 'lib/Dnsruby/Cache.rb', line 90 def (m) @expiration = get_expiration(m) = Message.decode(m.encode) .cached = true end |
#to_s ⇒ Object
128 129 130 |
# File 'lib/Dnsruby/Cache.rb', line 128 def to_s return "#{self.message}" end |