Class: Dnsruby::Cache::CacheData
- Inherits:
-
Object
- Object
- Dnsruby::Cache::CacheData
- Defined in:
- lib/dnsruby/cache.rb
Overview
:nodoc: all
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
Returns a new instance of CacheData.
151 152 153 154 155 |
# File 'lib/dnsruby/cache.rb', line 151 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.
117 118 119 |
# File 'lib/dnsruby/cache.rb', line 117 def expiration @expiration end |
Instance Method Details
#get_expiration(m) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/dnsruby/cache.rb', line 136 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
123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/dnsruby/cache.rb', line 123 def m = Message.decode(@message.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
118 119 120 121 122 |
# File 'lib/dnsruby/cache.rb', line 118 def (m) @expiration = get_expiration(m) @message = Message.decode(m.encode(true)) @message.cached = true end |
#to_s ⇒ Object
156 157 158 |
# File 'lib/dnsruby/cache.rb', line 156 def to_s return "#{self.}" end |