MCPcopy Create free account
hub / github.com/rthalley/dnspython / get

Method get

dns/resolver.py:452–470  ·  view source on GitHub ↗

Get the answer associated with *key*. Returns None if no answer is cached for the key. *key*, a ``(dns.name.Name, dns.rdatatype.RdataType, dns.rdataclass.RdataClass)`` tuple whose values are the query name, rdtype, and rdclass respectively. Returns a ``dns.resolver

(self, key: CacheKey)

Source from the content-addressed store, hash-verified

450 self.next_cleaning = now + self.cleaning_interval
451
452 def get(self, key: CacheKey) -> Answer | None:
453 """Get the answer associated with *key*.
454
455 Returns None if no answer is cached for the key.
456
457 *key*, a ``(dns.name.Name, dns.rdatatype.RdataType, dns.rdataclass.RdataClass)``
458 tuple whose values are the query name, rdtype, and rdclass respectively.
459
460 Returns a ``dns.resolver.Answer`` or ``None``.
461 """
462
463 with self.lock:
464 self._maybe_clean()
465 v = self.data.get(key)
466 if v is None or v.expiration <= time.time():
467 self.statistics.misses += 1
468 return None
469 self.statistics.hits += 1
470 return v
471
472 def put(self, key: CacheKey, value: Answer) -> None:
473 """Associate key and value in the cache.

Callers 12

testCacheExpirationMethod · 0.95
testCacheNonCleaningMethod · 0.95
__add__Method · 0.45
canonical_nameMethod · 0.45
getMethod · 0.45
get_hits_for_keyMethod · 0.45
putMethod · 0.45
flushMethod · 0.45
next_requestMethod · 0.45
_enrich_nameserversMethod · 0.45
zone_for_nameFunction · 0.45

Calls 2

_maybe_cleanMethod · 0.95
timeMethod · 0.80

Tested by 2

testCacheExpirationMethod · 0.76
testCacheNonCleaningMethod · 0.76