pub enum CacheStrategy {
Lru(NonZero<usize>),
NoCache,
}Expand description
Strategy for caching topic matching results
Controls how topic match results are cached to optimize performance. Different strategies trade memory usage for lookup speed.
Variants§
Lru(NonZero<usize>)
Use LRU (Least Recently Used) cache with a fixed size
Maintains a cache of recently matched topics. When the cache is full, the least recently used entry is evicted. Provides good performance for workloads with repeated topic patterns.
Note: This variant is only available with the lru-cache feature enabled.
§Example
use std::num::NonZeroUsize;
use mqtt_topic_engine::CacheStrategy;
let cache = CacheStrategy::Lru(NonZeroUsize::new(100).unwrap());NoCache
No caching - always create new TopicPath instances
Disables caching entirely. Use this when:
- Topic patterns are rarely repeated
- Memory is constrained
- Simplicity is preferred over performance
Implementations§
Source§impl CacheStrategy
impl CacheStrategy
Sourcepub fn new(capacity: usize) -> CacheStrategy
pub fn new(capacity: usize) -> CacheStrategy
Create a new cache strategy with the specified capacity
Returns NoCache if capacity is 0, otherwise returns Lru with the given capacity
(if lru-cache feature is enabled).
§Arguments
capacity- Maximum number of entries to cache (0 means no caching)
§Examples
use mqtt_topic_engine::CacheStrategy;
// Create no-cache strategy
let no_cache = CacheStrategy::new(0);
assert_eq!(no_cache, CacheStrategy::NoCache);With lru-cache feature:
// Create LRU cache with 100 entries
let cache = CacheStrategy::new(100);Sourcepub fn capacity(&self) -> Option<NonZero<usize>>
pub fn capacity(&self) -> Option<NonZero<usize>>
Returns the cache capacity if using LRU strategy
§Examples
use mqtt_topic_engine::CacheStrategy;
let no_cache = CacheStrategy::NoCache;
assert_eq!(no_cache.capacity(), None);With lru-cache feature:
use std::num::NonZeroUsize;
use mqtt_topic_engine::CacheStrategy;
let cache = CacheStrategy::new(100);
assert_eq!(cache.capacity(), Some(NonZeroUsize::new(100).unwrap()));Trait Implementations§
Source§impl Clone for CacheStrategy
impl Clone for CacheStrategy
Source§fn clone(&self) -> CacheStrategy
fn clone(&self) -> CacheStrategy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for CacheStrategy
Source§impl Debug for CacheStrategy
impl Debug for CacheStrategy
Source§impl Default for CacheStrategy
impl Default for CacheStrategy
Source§fn default() -> CacheStrategy
fn default() -> CacheStrategy
Default strategy is no caching
This ensures predictable behavior and minimal memory usage by default.
impl Eq for CacheStrategy
Source§impl PartialEq for CacheStrategy
impl PartialEq for CacheStrategy
Source§fn eq(&self, other: &CacheStrategy) -> bool
fn eq(&self, other: &CacheStrategy) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for CacheStrategy
Auto Trait Implementations§
impl Freeze for CacheStrategy
impl RefUnwindSafe for CacheStrategy
impl Send for CacheStrategy
impl Sync for CacheStrategy
impl Unpin for CacheStrategy
impl UnsafeUnpin for CacheStrategy
impl UnwindSafe for CacheStrategy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.