pub struct Manager<const N: usize>(/* private fields */);
Expand description
A shared LRU cache manager designed to manage a large volume of assets.
- Space optimized in-memory LRU (see pingora_lru).
- Instead of a single giant LRU, this struct shards the assets into
N
independent LRUs.
This allows EvictionManager::save() not to lock the entire cache manager while performing serialization.
Implementations§
Source§impl<const N: usize> Manager<N>
impl<const N: usize> Manager<N>
Sourcepub fn with_capacity(limit: usize, capacity: usize) -> Self
pub fn with_capacity(limit: usize, capacity: usize) -> Self
Create a Manager with the given size limit and estimated per shard capacity.
The capacity
is for preallocating to avoid reallocation cost when the LRU grows.
Sourcepub fn deserialize_shard(&self, buf: &[u8]) -> Result<()>
pub fn deserialize_shard(&self, buf: &[u8]) -> Result<()>
Deserialize a shard
Shard number is not needed because the key itself will hash to the correct shard.
Trait Implementations§
Source§impl<const N: usize> EvictionManager for Manager<N>
impl<const N: usize> EvictionManager for Manager<N>
Source§fn total_size(&self) -> usize
fn total_size(&self) -> usize
Total size of the cache in bytes tracked by this eviction manager
Source§fn total_items(&self) -> usize
fn total_items(&self) -> usize
Number of assets tracked by this eviction manager
Source§fn evicted_size(&self) -> usize
fn evicted_size(&self) -> usize
Number of bytes that are already evicted Read more
Source§fn evicted_items(&self) -> usize
fn evicted_items(&self) -> usize
Number of assets that are already evicted Read more
Source§fn admit(
&self,
item: CompactCacheKey,
size: usize,
_fresh_until: SystemTime,
) -> Vec<CompactCacheKey>
fn admit( &self, item: CompactCacheKey, size: usize, _fresh_until: SystemTime, ) -> Vec<CompactCacheKey>
Admit an item Read more
Source§fn remove(&self, item: &CompactCacheKey)
fn remove(&self, item: &CompactCacheKey)
Remove an item from the eviction manager. Read more
Source§fn access(
&self,
item: &CompactCacheKey,
size: usize,
_fresh_until: SystemTime,
) -> bool
fn access( &self, item: &CompactCacheKey, size: usize, _fresh_until: SystemTime, ) -> bool
Access an item that should already be in cache. Read more
Source§fn peek(&self, item: &CompactCacheKey) -> bool
fn peek(&self, item: &CompactCacheKey) -> bool
Peek into the manager to see if the item is already tracked by the system Read more
Auto Trait Implementations§
impl<const N: usize> !Freeze for Manager<N>
impl<const N: usize> !RefUnwindSafe for Manager<N>
impl<const N: usize> Send for Manager<N>
impl<const N: usize> Sync for Manager<N>
impl<const N: usize> Unpin for Manager<N>
impl<const N: usize> UnwindSafe for Manager<N>
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