pub struct LruCache<K: LruKey, T: LruValue> {
shards: Vec<Mutex<LruCacheShard<K, T>>>,
shard_usages: Vec<Arc<AtomicUsize>>,
shard_lru_usages: Vec<Arc<AtomicUsize>>,
listener: Option<Arc<dyn LruCacheEventListener<K = K, T = T>>>,
}
Fields§
§shards: Vec<Mutex<LruCacheShard<K, T>>>
§shard_usages: Vec<Arc<AtomicUsize>>
§shard_lru_usages: Vec<Arc<AtomicUsize>>
§listener: Option<Arc<dyn LruCacheEventListener<K = K, T = T>>>
Implementations§
source§impl<K: LruKey, T: LruValue> LruCache<K, T>
impl<K: LruKey, T: LruValue> LruCache<K, T>
pub fn new( num_shards: usize, capacity: usize, high_priority_ratio: usize, ) -> Self
pub fn with_event_listener( num_shards: usize, capacity: usize, high_priority_ratio: usize, listener: Arc<dyn LruCacheEventListener<K = K, T = T>>, ) -> Self
fn new_inner( num_shards: usize, capacity: usize, high_priority_ratio: usize, listener: Option<Arc<dyn LruCacheEventListener<K = K, T = T>>>, ) -> Self
pub fn contains(self: &Arc<Self>, hash: u64, key: &K) -> bool
pub fn lookup( self: &Arc<Self>, hash: u64, key: &K, ) -> Option<CacheableEntry<K, T>>
pub fn lookup_for_request( self: &Arc<Self>, hash: u64, key: K, ) -> LookupResult<K, T>
unsafe fn release(&self, handle: *mut LruHandle<K, T>)
unsafe fn inc_reference(&self, handle: *mut LruHandle<K, T>)
pub fn insert( self: &Arc<Self>, key: K, hash: u64, charge: usize, value: T, priority: CachePriority, ) -> CacheableEntry<K, T>
pub fn clear_pending_request(&self, key: &K, hash: u64)
pub fn erase(&self, hash: u64, key: &K)
pub fn get_memory_usage(&self) -> usize
pub fn get_lru_usage(&self) -> usize
fn shard(&self, hash: u64) -> usize
source§impl<K: LruKey + Clone + 'static, T: LruValue + 'static> LruCache<K, T>
impl<K: LruKey + Clone + 'static, T: LruValue + 'static> LruCache<K, T>
Only implement lookup_with_request_dedup
for static
values, as they can be sent across tokio spawned futures.
pub fn lookup_with_request_dedup<F, E, VC>( self: &Arc<Self>, hash: u64, key: K, priority: CachePriority, fetch_value: F, ) -> LookupResponse<K, T, E> ⓘ
Auto Trait Implementations§
impl<K, T> Freeze for LruCache<K, T>
impl<K, T> !RefUnwindSafe for LruCache<K, T>
impl<K, T> Send for LruCache<K, T>
impl<K, T> Sync for LruCache<K, T>
impl<K, T> Unpin for LruCache<K, T>where
K: Unpin,
impl<K, T> !UnwindSafe for LruCache<K, T>
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
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request
§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Err = Infallible
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>
source§impl<M> MetricVecRelabelExt for M
impl<M> MetricVecRelabelExt for M
source§fn relabel(
self,
metric_level: MetricLevel,
relabel_threshold: MetricLevel,
) -> RelabeledMetricVec<M>
fn relabel( self, metric_level: MetricLevel, relabel_threshold: MetricLevel, ) -> RelabeledMetricVec<M>
Equivalent to
RelabeledMetricVec::with_metric_level
.source§fn relabel_n(
self,
metric_level: MetricLevel,
relabel_threshold: MetricLevel,
relabel_num: usize,
) -> RelabeledMetricVec<M>
fn relabel_n( self, metric_level: MetricLevel, relabel_threshold: MetricLevel, relabel_num: usize, ) -> RelabeledMetricVec<M>
Equivalent to
RelabeledMetricVec::with_metric_level_relabel_n
.source§fn relabel_debug_1(
self,
relabel_threshold: MetricLevel,
) -> RelabeledMetricVec<M>
fn relabel_debug_1( self, relabel_threshold: MetricLevel, ) -> RelabeledMetricVec<M>
Equivalent to
RelabeledMetricVec::with_metric_level_relabel_n
with metric_level
set to
MetricLevel::Debug
and relabel_num
set to 1.