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.
143 144 145 146 147 |
# File 'lib/dnsruby/cache.rb', line 143 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.
109 110 111 |
# File 'lib/dnsruby/cache.rb', line 109 def expiration @expiration end |
Instance Method Details
#get_expiration(m) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/dnsruby/cache.rb', line 128 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
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/dnsruby/cache.rb', line 115 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
110 111 112 113 114 |
# File 'lib/dnsruby/cache.rb', line 110 def (m) @expiration = get_expiration(m) @message = Message.decode(m.encode) @message.cached = true end |
#to_s ⇒ Object
148 149 150 |
# File 'lib/dnsruby/cache.rb', line 148 def to_s return "#{self.}" end |