Skip to main content

PartitionedCache

Struct PartitionedCache 

Source
pub struct PartitionedCache {
    pub default_partition: String,
    /* private fields */
}
Expand description

A cache composed of multiple named CachePartitions.

Each partition is isolated: operations on one partition never evict entries from another. A configurable default_partition is used when callers omit the partition name.

Fields§

§default_partition: String

Name of the default partition used by *_default methods.

Implementations§

Source§

impl PartitionedCache

Source

pub fn new( default_partition: impl Into<String>, default_capacity_bytes: usize, ) -> Self

Create a new PartitionedCache with a single default partition.

Source

pub fn add_partition(&mut self, name: impl Into<String>, max_bytes: usize)

Add a new named partition. If a partition with the same name already exists it is replaced.

Source

pub fn remove_partition(&mut self, name: &str) -> bool

Remove a partition by name. Returns true if it existed.

The default partition cannot be removed.

Source

pub fn has_partition(&self, name: &str) -> bool

Return true if a partition with name exists.

Source

pub fn partition_names(&self) -> Vec<String>

Return a list of all partition names.

Source

pub fn get(&mut self, partition: &str, key: &str) -> Option<&CacheEntry>

Get the entry for key from partition.

Returns None if the partition does not exist, the key is absent, or the entry has expired.

Source

pub fn put(&mut self, partition: &str, key: String, entry: CacheEntry)

Insert (key, entry) into partition.

If partition does not exist the call is silently dropped.

Source

pub fn remove(&mut self, partition: &str, key: &str) -> bool

Remove key from partition. Returns true if it was found.

Source

pub fn evict_from(&mut self, partition: &str, bytes: usize) -> usize

Evict bytes of data from partition.

Returns the number of bytes freed.

Source

pub fn partition_stats(&self, partition: &str) -> Option<PartitionStats>

Return partition statistics for partition, or None if it does not exist.

Source

pub fn all_stats(&self) -> Vec<PartitionStats>

Return statistics for all partitions.

Source

pub fn total_entries(&self) -> usize

Total number of entries across all partitions.

Source

pub fn total_used_bytes(&self) -> usize

Total bytes used across all partitions.

Source

pub fn purge_all_expired(&mut self) -> usize

Purge expired entries from all partitions. Returns total count removed.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.