DescriptorCache

Struct DescriptorCache 

Source
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 enabled

Implementations§

Source§

impl DescriptorCache

Source

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
Source

pub fn with_consensus_ttl(self, ttl: Duration) -> Self

Sets the TTL for consensus documents.

Source

pub fn with_server_descriptor_ttl(self, ttl: Duration) -> Self

Sets the TTL for server descriptors.

Source

pub fn with_microdescriptor_ttl(self, ttl: Duration) -> Self

Sets the TTL for microdescriptors.

Source

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.

Source

pub fn get_consensus(&self) -> Option<NetworkStatusDocument>

Retrieves the cached consensus document if available and not expired.

Source

pub fn put_consensus(&self, consensus: NetworkStatusDocument)

Stores a consensus document in the cache.

Source

pub fn get_server_descriptor( &self, fingerprint: &str, ) -> Option<ServerDescriptor>

Retrieves a cached server descriptor by fingerprint.

Source

pub fn put_server_descriptor( &self, fingerprint: String, descriptor: ServerDescriptor, )

Stores a server descriptor in the cache.

Source

pub fn get_microdescriptor(&self, digest: &str) -> Option<Microdescriptor>

Retrieves a cached microdescriptor by digest.

Source

pub fn put_microdescriptor(&self, digest: String, descriptor: Microdescriptor)

Stores a microdescriptor in the cache.

Source

pub fn clear(&self)

Clears all cached entries.

Source

pub fn evict_expired(&self)

Removes expired entries from the cache.

Source

pub fn stats(&self) -> CacheStats

Returns the current cache statistics.

Source

pub fn len(&self) -> usize

Returns the number of entries currently in the cache.

Source

pub fn is_empty(&self) -> bool

Returns true if the cache is empty.

Trait Implementations§

Source§

impl Clone for DescriptorCache

Source§

fn clone(&self) -> DescriptorCache

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DescriptorCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DescriptorCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V