pub struct Cache { /* private fields */ }Expand description
Event ID deduplication cache using std::sync::Mutex with LRU eviction
This is the winning strategy from benchmarks - fastest under realistic multi-threaded relay pool scenarios (10-20 concurrent connections).
Pros:
- Automatic LRU eviction, bounded memory
- Excellent performance under realistic concurrency
- Zero external dependencies beyond lru crate
- Simple, predictable behavior
Implementations§
Source§impl Cache
impl Cache
Sourcepub fn insert(&self, id: String) -> bool
pub fn insert(&self, id: String) -> bool
Insert an event ID into the cache
Returns true if this is a new event (not seen before),
false if the event was already in the cache (duplicate).
§Example
use nostro2_cache::Cache;
let cache = Cache::new(10_000);
if cache.insert("event_id_123".to_string()) {
println!("New event!");
} else {
println!("Duplicate, skip");
}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Cache
impl RefUnwindSafe for Cache
impl Send for Cache
impl Sync for Cache
impl Unpin for Cache
impl UnwindSafe for Cache
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
Mutably borrows from an owned value. Read more