Class: EventMachine::DnsCache::Cache
- Inherits:
-
Object
- Object
- EventMachine::DnsCache::Cache
- Defined in:
- lib/em/dns_cache.rb
Instance Method Summary collapse
- #add(domain, value, expiration) ⇒ Object
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
- #retrieve(domain) ⇒ Object
Constructor Details
#initialize ⇒ Cache
Returns a new instance of Cache.
14 15 16 |
# File 'lib/em/dns_cache.rb', line 14 def initialize @hash = {} end |
Instance Method Details
#add(domain, value, expiration) ⇒ Object
17 18 19 20 |
# File 'lib/em/dns_cache.rb', line 17 def add domain, value, expiration ex = ((expiration < 0) ? :none : (Time.now + expiration)) @hash[domain] = [ex, value] end |
#retrieve(domain) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/em/dns_cache.rb', line 21 def retrieve domain if @hash.has_key?(domain) d = @hash[domain] if d.first != :none and d.first < Time.now @hash.delete(domain) nil else d.last end end end |