Skip to main content

ManagedCache

Struct ManagedCache 

Source
pub struct ManagedCache { /* private fields */ }
Expand description

A named, self-expiring, size-bounded cache (see the module doc).

Implementations§

Source§

impl ManagedCache

Source

pub fn create_cache(name: &str, expiry_ms: u64) -> Arc<ManagedCache>

Obtain (or create) the named cache with the default 2000-item bound (Java createCache(name, expiryMs)). Idempotent by name: a later call returns the existing instance unchanged — the first creation’s parameters win, later parameters are ignored (Java semantics).

Source

pub fn create_cache_with_limit( name: &str, expiry_ms: u64, max_items: u64, ) -> Arc<ManagedCache>

Obtain (or create) the named cache (Java createCache(name, expiryMs, maxItems)). Expiry is clamped to [1 s, ~100 years].

Source

pub fn get_instance(name: &str) -> Option<Arc<ManagedCache>>

Resolve a cache by name from any module (Java getInstance).

Source

pub fn get_cache_collection() -> BTreeMap<String, Arc<ManagedCache>>

Sorted snapshot of every registered cache for ops introspection (Java getCacheCollection returns the live map — design §5).

Source

pub fn put<V: Any + Send + Sync>(&self, key: &str, value: V)

Store a value (Java put) — stamps last_write; empty key = no-op. NEVER pass a pre-wrapped Arc/CacheValue here — it would nest (Arc<Arc<T>>) and get_as::<T> would miss; use Self::put_arc for values that are already reference-counted.

Source

pub fn put_arc(&self, key: &str, value: CacheValue)

Store an already-wrapped value — stamps last_write; empty key = no-op.

Source

pub fn get(&self, key: &str) -> Option<CacheValue>

Fetch a value (Java get) — stamps last_read on any non-empty-key call, hit or miss (Java stamps before the lookup).

Source

pub fn get_as<T: Any + Send + Sync>(&self, key: &str) -> Option<Arc<T>>

Typed fetch: None on absence OR type mismatch — the Rust analog of the cast at a Java call site.

Source

pub fn exists(&self, key: &str) -> bool

Java exists — delegates to get, so it inherits the last_read stamp.

Source

pub fn remove(&self, key: &str)

Java remove — stamps last_write even when the key is absent.

Source

pub fn clear(&self)

Java clear is three operations: stamp lastReset, invalidateAll(), cleanUp() — the cleanup keeps size() honest immediately after a clear. Emits no log (only clean_up logs).

Source

pub fn clean_up(&self)

Java cleanUp — apply pending maintenance (expiry sweep, deferred evictions) now.

Source

pub fn name(&self) -> &str

Cache name (Java getName).

Source

pub fn expiry_ms(&self) -> u64

The clamped expiry in ms (Java getExpiry returns the clamped value).

Source

pub fn max_items(&self) -> u64

Capacity bound (Java getMaxItems).

Source

pub fn size(&self) -> u64

Estimated entry count (Java size() = Caffeine estimatedSize; moka entry_count — call Self::clean_up first for freshness).

Source

pub fn entries(&self) -> Vec<(String, CacheValue)>

Snapshot of the unexpired entries (Java getMap returns a live ConcurrentMap view; Rust hands out no live guard — design §5).

Source

pub fn last_read(&self) -> i64

Epoch ms of the last get/exists (Java getLastRead; 0 = never).

Source

pub fn last_write(&self) -> i64

Epoch ms of the last put/remove (Java getLastWrite; 0 = never).

Source

pub fn last_reset(&self) -> i64

Epoch ms of construction or the last clear (Java getLastReset).

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V