/// Create new backend w/o any known keys.
///
/// The inner backend MUST NOT contain any data at this point, otherwise we will not track any resource consumption
/// for these entries.
///
/// # Panic
/// - Panics if the given ID is already used within the given pool.
/// - If the inner backend is not empty.
Create new backend w/o any known keys.
The inner backend MUST NOT contain any data at this point, otherwise we will not track any resource consumption
for these entries.
Create new backend w / o any known keys . The inner backend MUST NOT contain any data at this point otherwise we will not track any resource consumption for these entries .
pub fn new(
        inner_backend: Box<dyn CacheBackend<K = K, V = V>>,
        pool: Arc<ResourcePool<S>>,
        id: &'static str,
        resource_estimator: Arc<dyn ResourceEstimator<K = K, V = V, S = S>>,
    ) -> Self {
        assert!(inner_backend.is_empty(), "inner backend is not empty");
        let metric_count = pool
            .metric_registry
            .register_metric::<U64Gauge>(
                "cache_lru_member_count",
                "Number of entries for a given LRU cache pool member",
            )
            .recorder(&[("pool", pool.name), ("member", id)]);
        let metric_usage = pool
            .metric_registry
            .register_metric::<U64Gauge>(
                "cache_lru_member_usage",
                "Resource usage of a given LRU cache pool member",
            )
            .recorder(&[("pool", pool.name), ("member", id), ("unit", S::unit())]);
        let inner = Arc::new(Mutex::new(LruBackendInner {
            inner_backend,
            last_used: AddressableHeap::new(),
            metric_count,
            metric_usage,
        }));
        pool.inner.lock().register_member(
            id,
            Box::new(PoolMemberImpl {
                inner: Arc::clone(&inner),
            }),
        );
        Self {
            id,
            inner,
            pool,
            resource_estimator,
        }
    }
pub fn new ( inner_backend : Box < dyn CacheBackend < K = K , V = V > > , pool : Arc < ResourcePool < S > > , id : & ' static str , resource_estimator : Arc < dyn ResourceEstimator < K = K , V = V , S = S > > , ) -> Self { assert ! ( inner_backend is_empty ( ) " " ) ; let metric_count = pool . metric_registry . register_metric :: < U64Gauge > ( " " , " " , ) . recorder ( & [ ( " " , pool . name ) , ( " " , id ) ] ) ; let metric_usage = pool . metric_registry . register_metric :: < U64Gauge > ( " " , " " , ) . recorder ( & [ ( " " , pool . name ) , ( " " , id ) , ( " " , S :: unit ( ) ) ] ) ; let inner = Arc :: new ( Mutex :: new ( LruBackendInner { inner_backend , last_used : AddressableHeap :: new ( ) , metric_count , metric_usage , } ) ) ; pool . inner . lock ( ) . register_member ( id , Box :: new ( PoolMemberImpl { inner : Arc :: clone ( & inner ) , } ) , ) ; Self { id , inner , pool , resource_estimator , } }
Create new backend w/o any known keys.
Create new backend w / o any known keys .
inner_backend
Box<dyn CacheBackend<K = K, V = V>>
pool
Arc<ResourcePool<S>>
id
&'static str
resource_estimator
Arc<dyn ResourceEstimator<K = K, V = V, S = S>>
panic
Panics if the given ID is already used within the given pool.
If the inner backend is not empty.
Panics if the given ID is already used within the given pool . If the inner backend is not empty .