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: StringName of the default partition used by *_default methods.
Implementations§
Source§impl PartitionedCache
impl PartitionedCache
Sourcepub fn new(
default_partition: impl Into<String>,
default_capacity_bytes: usize,
) -> Self
pub fn new( default_partition: impl Into<String>, default_capacity_bytes: usize, ) -> Self
Create a new PartitionedCache with a single default partition.
Sourcepub fn add_partition(&mut self, name: impl Into<String>, max_bytes: usize)
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.
Sourcepub fn remove_partition(&mut self, name: &str) -> bool
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.
Sourcepub fn has_partition(&self, name: &str) -> bool
pub fn has_partition(&self, name: &str) -> bool
Return true if a partition with name exists.
Sourcepub fn partition_names(&self) -> Vec<String>
pub fn partition_names(&self) -> Vec<String>
Return a list of all partition names.
Sourcepub fn get(&mut self, partition: &str, key: &str) -> Option<&CacheEntry>
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.
Sourcepub fn put(&mut self, partition: &str, key: String, entry: CacheEntry)
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.
Sourcepub fn remove(&mut self, partition: &str, key: &str) -> bool
pub fn remove(&mut self, partition: &str, key: &str) -> bool
Remove key from partition. Returns true if it was found.
Sourcepub fn evict_from(&mut self, partition: &str, bytes: usize) -> usize
pub fn evict_from(&mut self, partition: &str, bytes: usize) -> usize
Evict bytes of data from partition.
Returns the number of bytes freed.
Sourcepub fn partition_stats(&self, partition: &str) -> Option<PartitionStats>
pub fn partition_stats(&self, partition: &str) -> Option<PartitionStats>
Return partition statistics for partition, or None if it does not
exist.
Sourcepub fn all_stats(&self) -> Vec<PartitionStats>
pub fn all_stats(&self) -> Vec<PartitionStats>
Return statistics for all partitions.
Sourcepub fn total_entries(&self) -> usize
pub fn total_entries(&self) -> usize
Total number of entries across all partitions.
Sourcepub fn total_used_bytes(&self) -> usize
pub fn total_used_bytes(&self) -> usize
Total bytes used across all partitions.
Sourcepub fn purge_all_expired(&mut self) -> usize
pub fn purge_all_expired(&mut self) -> usize
Purge expired entries from all partitions. Returns total count removed.