Class: Dnsruby::Cache
- Inherits:
-
Object
show all
- Defined in:
- lib/Dnsruby/Cache.rb
Overview
Defined Under Namespace
Classes: CacheData, CacheKey
Class Method Summary
collapse
Instance Method Summary
collapse
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
.delete(qname, qtype, qclass = Classes.IN) ⇒ Object
63
64
65
66
67
68
|
# File 'lib/Dnsruby/Cache.rb', line 63
def Cache.delete(qname, qtype, qclass = Classes.IN)
key = CacheKey.new(qname, qtype, qclass)
@mutex.synchronize {
@cache.delete(key)
}
end
|
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(message)
q = message.question[0]
key = CacheKey.new(q.qname, q.qtype, q.qclass).to_s
data = CacheData.new(message)
@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)
qn = Name.create(qname)
qn.absolute = true
key = CacheKey.new(qn, qtype, qclass).to_s
@mutex.synchronize {
data = @cache[key]
if (!data)
return nil
end
if (data.expiration <= Time.now.to_i)
@cache.delete(key)
TheLog.debug("CACHE lookup stale\n")
return nil
end
m = data.message
TheLog.debug("CACHE found\n")
return m
}
end
|