pub fn weighted<W>(name: &'static str, capacity: u64, weigher: W) -> Self
    where
        W: Fn(&K, &V) -> u32 + Send + Sync + 'static,
    {
        tracing::info!("Configured LRU cache `{name}` with capacity {capacity}B");
        let metrics = &METRICS[&name.into()];
        if let Err(err) = metrics.lru_info.set(LruCacheConfig { capacity }) {
            tracing::warn!(
                "LRU cache `{name}` was already created with config {:?}; new config: {:?}",
                metrics.lru_info.get(),
                err.into_inner()
            );
        }

        let cache = if capacity == 0 {
            None
        } else {
            Some(
                MokaBase::<K, V>::builder()
                    .weigher(weigher)
                    .max_capacity(capacity)
                    .build(),
            )
        };

        Self { metrics, cache }
    }
Creates a new cache with a custom weighting function.

# Panics

Panics if an invalid cache capacity is provided.
core/lib/state/src/cache/lru_cache.rs