Skip to main content

BoundedLruCache

Struct BoundedLruCache 

Source
pub struct BoundedLruCache<K, V>
where K: Hash + Eq + Clone,
{ /* private fields */ }
Expand description

Workspace indexing and refactoring orchestration. Thread-safe bounded LRU cache.

Implements a least-recently-used eviction policy with configurable size limits and optional TTL expiration.

§Type Parameters

  • K - Cache key type (must implement Hash + Eq)
  • V - Cache value type

§Performance

  • Insert: O(1) amortized
  • Get: O(1) amortized
  • Eviction: O(1) amortized

Implementations§

Source§

impl<K, V> BoundedLruCache<K, V>
where K: Hash + Eq + Clone,

Source

pub fn new(config: CacheConfig) -> BoundedLruCache<K, V>

Create a new bounded LRU cache with the given configuration.

§Arguments
  • config - Cache configuration (size limits, TTL, etc.)
§Returns

A new bounded LRU cache instance.

§Examples
use perl_workspace_index::workspace::cache::{BoundedLruCache, CacheConfig};

let config = CacheConfig {
    max_items: 1000,
    max_bytes: 10 * 1024 * 1024, // 10MB
    ttl: None,
};
let cache: BoundedLruCache<String, String> = BoundedLruCache::new(config);
Source

pub fn default() -> BoundedLruCache<K, V>

Create a new cache with default configuration.

§Returns

A new bounded LRU cache with default limits (10,000 items, 50MB).

§Examples
use perl_workspace_index::workspace::cache::BoundedLruCache;

let cache: BoundedLruCache<String, String> = BoundedLruCache::default();
Source

pub fn insert_with_size(&self, key: K, value: V, size_bytes: usize) -> bool

Insert a value into the cache.

If the cache is at capacity, the least recently used entry will be evicted.

§Arguments
  • key - Cache key
  • value - Value to cache
  • size_bytes - Size of the value in bytes (for memory tracking)
§Returns

true if the value was inserted, false if evicted due to size limits.

§Examples
use perl_workspace_index::workspace::cache::BoundedLruCache;

let mut cache = BoundedLruCache::default();
cache.insert_with_size("key", "value", 5);
Source

pub fn insert(&self, key: K, value: V)
where V: EstimateSize,

Insert a value into the cache with estimated size.

Uses a simple size estimation based on the value’s memory representation.

§Arguments
  • key - Cache key
  • value - Value to cache
§Returns

true if the value was inserted, false if evicted.

§Examples
use perl_workspace_index::workspace::cache::BoundedLruCache;

let mut cache = BoundedLruCache::default();
cache.insert("key", "value");
Source

pub fn get(&self, key: &K) -> Option<V>
where V: Clone,

Get a value from the cache.

Returns None if the key is not found or the entry has expired.

§Arguments
  • key - Cache key to look up
§Returns

Some(&V) if found and not expired, None otherwise.

§Examples
use perl_workspace_index::workspace::cache::BoundedLruCache;

let mut cache = BoundedLruCache::default();
cache.insert("key", "value");
assert_eq!(cache.get("key"), Some(&"value"));
Source

pub fn peek(&self, key: &K) -> Option<V>
where V: Clone,

Peek a value from the cache without changing hit/miss counters.

Expired entries are still removed so stale data does not linger.

Source

pub fn remove(&self, key: &K) -> Option<V>
where V: Clone,

Remove a value from the cache.

§Arguments
  • key - Cache key to remove
§Returns

Some(V) if the entry was removed, None if not found.

§Examples
use perl_workspace_index::workspace::cache::BoundedLruCache;

let mut cache = BoundedLruCache::default();
cache.insert("key", "value");
assert_eq!(cache.remove("key"), Some("value"));
Source

pub fn clear(&self)

Clear all entries from the cache.

§Examples
use perl_workspace_index::workspace::cache::BoundedLruCache;

let mut cache = BoundedLruCache::default();
cache.insert("key", "value");
cache.clear();
assert!(cache.is_empty());
Source

pub fn is_empty(&self) -> bool

Check if the cache is empty.

§Returns

true if the cache contains no entries, false otherwise.

Source

pub fn len(&self) -> usize

Get the number of items in the cache.

§Returns

The current number of cached items.

Source

pub fn stats(&self) -> CacheStats

Get cache statistics.

§Returns

A snapshot of the cache statistics.

§Examples
use perl_workspace_index::workspace::cache::BoundedLruCache;

let cache = BoundedLruCache::default();
let stats = cache.stats();
assert_eq!(stats.hits, 0);
Source

pub fn config(&self) -> &CacheConfig

Get the cache configuration.

§Returns

The cache configuration.

Auto Trait Implementations§

§

impl<K, V> Freeze for BoundedLruCache<K, V>

§

impl<K, V> !RefUnwindSafe for BoundedLruCache<K, V>

§

impl<K, V> Send for BoundedLruCache<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for BoundedLruCache<K, V>
where K: Send, V: Send,

§

impl<K, V> Unpin for BoundedLruCache<K, V>

§

impl<K, V> UnsafeUnpin for BoundedLruCache<K, V>

§

impl<K, V> !UnwindSafe for BoundedLruCache<K, V>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more