pub struct SharedCache {
cache: Arc<Mutex<Cache>>,
}
Expand description
A convenience wrapper around a Cache
which lets it be shared
between threads.
Invoking clone
on a SharedCache
gives a new instance which
refers to the same underlying Cache
object.
Fields§
§cache: Arc<Mutex<Cache>>
Implementations§
Sourcepub fn with_desired_size(desired_size: usize) -> Self
pub fn with_desired_size(desired_size: usize) -> Self
Create a new cache with the given desired size.
Sourcepub fn get(&self, name: &DomainName, qtype: QueryType) -> Vec<ResourceRecord>
pub fn get(&self, name: &DomainName, qtype: QueryType) -> Vec<ResourceRecord>
Get an entry from the cache.
The TTL in the returned ResourceRecord
is relative to the
current time - not when the record was inserted into the
cache.
§Panics
If the mutex has been poisoned.
Sourcepub fn get_without_checking_expiration(
&self,
name: &DomainName,
qtype: QueryType,
) -> Vec<ResourceRecord>
pub fn get_without_checking_expiration( &self, name: &DomainName, qtype: QueryType, ) -> Vec<ResourceRecord>
Like get
, but may return expired entries.
Consumers MUST check that the TTL of a record is nonzero before using it!
§Panics
If the mutex has been poisoned.
Sourcepub fn insert(&self, record: &ResourceRecord)
pub fn insert(&self, record: &ResourceRecord)
Insert an entry into the cache.
It is not inserted if its TTL is zero or negative.
This may make the cache grow beyond the desired size.
§Panics
If the mutex has been poisoned.
Sourcepub fn insert_all(&self, records: &[ResourceRecord])
pub fn insert_all(&self, records: &[ResourceRecord])
Insert multiple entries into the cache.
This is more efficient than calling insert
multiple times, as it locks
the cache just once.
Records with a TTL of zero or negative are skipped.
This may make the cache grow beyond the desired size.
§Panics
If the mutex has been poisoned.
Trait Implementations§
Source§fn clone(&self) -> SharedCache
fn clone(&self) -> SharedCache
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more