Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/policy/lru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
//! };
//! use std::sync::Arc;
//!
//! // Single-threaded usage
//! // Single-threaded usage (non-concurrent)
//! let mut cache: LruCore<u32, String> = LruCore::new(100);
//! cache.insert(1, Arc::new("page_data".to_string()));
//!
Expand All @@ -241,6 +241,17 @@
//! println!("Peeked: {}", value); // returns Arc<String>
//! }
//!
//! // Multi-threaded usage with thread-safe wrapper
//! let cache: ConcurrentLruCache<u32, String> = ConcurrentLruCache::new(100);
//!
//! // Clone the handle and send to other threads; internal access is synchronized.
//! let cache_clone = cache.clone();
//! cache_clone.insert(2, Arc::new("other_page".to_string()));
//!
//! if let Some(value) = cache_clone.get(&2) {
//! println!("Concurrent got: {}", value); // safe across threads
//! }
//!
//! // Evict least recently used
//! if let Some((key, value)) = cache.pop_lru() {
//! println!("Evicted key={}, value={}", key, value);
Expand Down Expand Up @@ -312,7 +323,7 @@
use crate::metrics::snapshot::LruMetricsSnapshot;
#[cfg(feature = "metrics")]
use crate::metrics::traits::{
CoreMetricsRecorder, LruMetricsReadRecorder, LruMetricsRecorder, MetricsSnapshotProvider,

Check failure on line 326 in src/policy/lru.rs

View workflow job for this annotation

GitHub Actions / Clippy

unused import: `LruMetricsReadRecorder`

Check failure on line 326 in src/policy/lru.rs

View workflow job for this annotation

GitHub Actions / MSRV Check

unused import: `LruMetricsReadRecorder`
};
use crate::prelude::ReadOnlyCache;
use crate::traits::{CoreCache, LruCacheTrait, MutableCache};
Expand Down Expand Up @@ -626,11 +637,11 @@
#[inline]
pub fn peek(&self, key: &K) -> Option<Arc<V>> {
#[cfg(feature = "metrics")]
(&self.metrics).record_peek_lru_call();
self.metrics.record_peek_lru_call();

Check failure on line 640 in src/policy/lru.rs

View workflow job for this annotation

GitHub Actions / Clippy

cannot borrow `self.metrics` as mutable, as it is behind a `&` reference

Check failure on line 640 in src/policy/lru.rs

View workflow job for this annotation

GitHub Actions / MSRV Check

cannot borrow `self.metrics` as mutable, as it is behind a `&` reference

if let Some(&id) = self.map.get(key) {
#[cfg(feature = "metrics")]
(&self.metrics).record_peek_lru_found();
self.metrics.record_peek_lru_found();

Check failure on line 644 in src/policy/lru.rs

View workflow job for this annotation

GitHub Actions / Clippy

cannot borrow `self.metrics` as mutable, as it is behind a `&` reference

Check failure on line 644 in src/policy/lru.rs

View workflow job for this annotation

GitHub Actions / MSRV Check

cannot borrow `self.metrics` as mutable, as it is behind a `&` reference
let node = self.arena.get(id).expect("peek: stale SlotId");
return Some(Arc::clone(&node.value));
}
Expand Down Expand Up @@ -680,13 +691,13 @@
#[inline]
fn peek_lru(&self) -> Option<(&K, &Arc<V>)> {
#[cfg(feature = "metrics")]
(&self.metrics).record_peek_lru_call();
self.metrics.record_peek_lru_call();

Check failure on line 694 in src/policy/lru.rs

View workflow job for this annotation

GitHub Actions / Clippy

cannot borrow `self.metrics` as mutable, as it is behind a `&` reference

Check failure on line 694 in src/policy/lru.rs

View workflow job for this annotation

GitHub Actions / MSRV Check

cannot borrow `self.metrics` as mutable, as it is behind a `&` reference

let tail_id = self.tail?;
let node = self.arena.get(tail_id)?;

#[cfg(feature = "metrics")]
(&self.metrics).record_peek_lru_found();
self.metrics.record_peek_lru_found();

Check failure on line 700 in src/policy/lru.rs

View workflow job for this annotation

GitHub Actions / Clippy

cannot borrow `self.metrics` as mutable, as it is behind a `&` reference

Check failure on line 700 in src/policy/lru.rs

View workflow job for this annotation

GitHub Actions / MSRV Check

cannot borrow `self.metrics` as mutable, as it is behind a `&` reference

Some((&node.key, &node.value))
}
Expand Down Expand Up @@ -714,19 +725,19 @@

fn recency_rank(&self, key: &K) -> Option<usize> {
#[cfg(feature = "metrics")]
(&self.metrics).record_recency_rank_call();
self.metrics.record_recency_rank_call();

Check failure on line 728 in src/policy/lru.rs

View workflow job for this annotation

GitHub Actions / Clippy

cannot borrow `self.metrics` as mutable, as it is behind a `&` reference

Check failure on line 728 in src/policy/lru.rs

View workflow job for this annotation

GitHub Actions / MSRV Check

cannot borrow `self.metrics` as mutable, as it is behind a `&` reference

let &target_id = self.map.get(key)?;
let mut rank = 0usize;
let mut current = self.head;

while let Some(id) = current {
#[cfg(feature = "metrics")]
(&self.metrics).record_recency_rank_scan_step();
self.metrics.record_recency_rank_scan_step();

Check failure on line 736 in src/policy/lru.rs

View workflow job for this annotation

GitHub Actions / Clippy

cannot borrow `self.metrics` as mutable, as it is behind a `&` reference

Check failure on line 736 in src/policy/lru.rs

View workflow job for this annotation

GitHub Actions / MSRV Check

cannot borrow `self.metrics` as mutable, as it is behind a `&` reference

if id == target_id {
#[cfg(feature = "metrics")]
(&self.metrics).record_recency_rank_found();
self.metrics.record_recency_rank_found();

Check failure on line 740 in src/policy/lru.rs

View workflow job for this annotation

GitHub Actions / Clippy

cannot borrow `self.metrics` as mutable, as it is behind a `&` reference

Check failure on line 740 in src/policy/lru.rs

View workflow job for this annotation

GitHub Actions / MSRV Check

cannot borrow `self.metrics` as mutable, as it is behind a `&` reference
return Some(rank);
}
rank += 1;
Expand Down
Loading