Skip to content

Commit

Permalink
refactor DNS cache implementation to use CacheKey enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Litr0 committed Jun 11, 2024
1 parent 4de52f3 commit c364b02
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/resolver_cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::dns_cache::DnsCache;
use crate::dns_cache::{CacheKey, DnsCache};
use crate::domain_name::DomainName;
use crate::message::resource_record::ResourceRecord;
use crate::message::type_qtype::Qtype;
Expand Down Expand Up @@ -41,6 +41,23 @@ impl ResolverCache {
}
}

/// Set the maximum size of the cache.
pub fn set_max_size(&mut self, size: NonZeroUsize) {
self.cache_answer.set_max_size(size);
self.cache_authority.set_max_size(size);
self.cache_additional.set_max_size(size);
}

/// See if the cache is empty.
pub fn is_empty(&self) -> bool {
self.cache_answer.is_empty() && self.cache_authority.is_empty() && self.cache_additional.is_empty()
}

/// See if an element is in the cache.
pub fn is_cached(&self, cache_key: CacheKey) -> bool {
self.cache_answer.is_cached(cache_key.clone()) || self.cache_authority.is_cached(cache_key.clone()) || self.cache_additional.is_cached(cache_key.clone())
}

/// Add an element to the answer cache.
pub fn add_answer(&mut self, domain_name: DomainName, resource_record: ResourceRecord, qtype: Option<Qtype>, qclass: Qclass, rcode: Option<Rcode>) {
if resource_record.get_ttl() > 0 {
Expand Down

0 comments on commit c364b02

Please sign in to comment.