pub struct ManagedCache { /* private fields */ }Expand description
A named, self-expiring, size-bounded cache (see the module doc).
Implementations§
Source§impl ManagedCache
impl ManagedCache
Sourcepub fn create_cache(name: &str, expiry_ms: u64) -> Arc<ManagedCache> ⓘ
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).
Sourcepub fn create_cache_with_limit(
name: &str,
expiry_ms: u64,
max_items: u64,
) -> Arc<ManagedCache> ⓘ
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].
Sourcepub fn get_instance(name: &str) -> Option<Arc<ManagedCache>>
pub fn get_instance(name: &str) -> Option<Arc<ManagedCache>>
Resolve a cache by name from any module (Java getInstance).
Sourcepub fn get_cache_collection() -> BTreeMap<String, Arc<ManagedCache>>
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).
Sourcepub fn put<V: Any + Send + Sync>(&self, key: &str, value: V)
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.
Sourcepub fn put_arc(&self, key: &str, value: CacheValue)
pub fn put_arc(&self, key: &str, value: CacheValue)
Store an already-wrapped value — stamps last_write; empty key = no-op.
Sourcepub fn get(&self, key: &str) -> Option<CacheValue>
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).
Sourcepub fn get_as<T: Any + Send + Sync>(&self, key: &str) -> Option<Arc<T>>
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.
Sourcepub fn exists(&self, key: &str) -> bool
pub fn exists(&self, key: &str) -> bool
Java exists — delegates to get, so it inherits the last_read stamp.
Sourcepub fn clear(&self)
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).
Sourcepub fn clean_up(&self)
pub fn clean_up(&self)
Java cleanUp — apply pending maintenance (expiry sweep, deferred
evictions) now.
Sourcepub fn expiry_ms(&self) -> u64
pub fn expiry_ms(&self) -> u64
The clamped expiry in ms (Java getExpiry returns the clamped value).
Sourcepub fn size(&self) -> u64
pub fn size(&self) -> u64
Estimated entry count (Java size() = Caffeine estimatedSize;
moka entry_count — call Self::clean_up first for freshness).
Sourcepub fn entries(&self) -> Vec<(String, CacheValue)>
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).
Sourcepub fn last_write(&self) -> i64
pub fn last_write(&self) -> i64
Epoch ms of the last put/remove (Java getLastWrite; 0 = never).
Sourcepub fn last_reset(&self) -> i64
pub fn last_reset(&self) -> i64
Epoch ms of construction or the last clear (Java getLastReset).