pub struct DescriptorCache { /* private fields */ }Expand description
In-memory cache for Tor descriptors.
Provides automatic expiration and LRU eviction for efficient memory usage. The cache is thread-safe and can be shared across multiple tasks.
§Example
use stem_rs::descriptor::cache::DescriptorCache;
use std::time::Duration;
let cache = DescriptorCache::new()
.with_consensus_ttl(Duration::from_secs(3600))
.with_max_entries(500);
// Cache is used automatically by Controller when enabledImplementations§
Source§impl DescriptorCache
impl DescriptorCache
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new descriptor cache with default settings.
Default settings:
- Consensus TTL: 3 hours
- Server descriptor TTL: 24 hours
- Microdescriptor TTL: 24 hours
- Max entries: 1000
Sourcepub fn with_consensus_ttl(self, ttl: Duration) -> Self
pub fn with_consensus_ttl(self, ttl: Duration) -> Self
Sets the TTL for consensus documents.
Sourcepub fn with_server_descriptor_ttl(self, ttl: Duration) -> Self
pub fn with_server_descriptor_ttl(self, ttl: Duration) -> Self
Sets the TTL for server descriptors.
Sourcepub fn with_microdescriptor_ttl(self, ttl: Duration) -> Self
pub fn with_microdescriptor_ttl(self, ttl: Duration) -> Self
Sets the TTL for microdescriptors.
Sourcepub fn with_max_entries(self, max: usize) -> Self
pub fn with_max_entries(self, max: usize) -> Self
Sets the maximum number of cached entries.
When this limit is reached, the least recently used entries are evicted.
Sourcepub fn get_consensus(&self) -> Option<NetworkStatusDocument>
pub fn get_consensus(&self) -> Option<NetworkStatusDocument>
Retrieves the cached consensus document if available and not expired.
Sourcepub fn put_consensus(&self, consensus: NetworkStatusDocument)
pub fn put_consensus(&self, consensus: NetworkStatusDocument)
Stores a consensus document in the cache.
Sourcepub fn get_server_descriptor( &self, fingerprint: &str, ) -> Option<ServerDescriptor>
pub fn get_server_descriptor( &self, fingerprint: &str, ) -> Option<ServerDescriptor>
Retrieves a cached server descriptor by fingerprint.
Sourcepub fn put_server_descriptor( &self, fingerprint: String, descriptor: ServerDescriptor, )
pub fn put_server_descriptor( &self, fingerprint: String, descriptor: ServerDescriptor, )
Stores a server descriptor in the cache.
Sourcepub fn get_microdescriptor(&self, digest: &str) -> Option<Microdescriptor>
pub fn get_microdescriptor(&self, digest: &str) -> Option<Microdescriptor>
Retrieves a cached microdescriptor by digest.
Sourcepub fn put_microdescriptor(&self, digest: String, descriptor: Microdescriptor)
pub fn put_microdescriptor(&self, digest: String, descriptor: Microdescriptor)
Stores a microdescriptor in the cache.
Sourcepub fn evict_expired(&self)
pub fn evict_expired(&self)
Removes expired entries from the cache.
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Returns the current cache statistics.
Trait Implementations§
Source§impl Clone for DescriptorCache
impl Clone for DescriptorCache
Source§fn clone(&self) -> DescriptorCache
fn clone(&self) -> DescriptorCache
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more