Skip to main content

ObjectCache

Trait ObjectCache 

Source
pub trait ObjectCache<K: Key, V: Value>: Send + Sync {
    // Required methods
    fn lookup_or_reserve<'a>(&'a self, key: &K) -> ObjectCacheResult<'a, V>;
    fn is_cacheable(&self, key: &K) -> bool;
    fn invalidate(&self, key: &K, value: Option<V>);
    fn clear(&self);

    // Provided method
    fn len(&self) -> usize { ... }
}

Required Methods§

Source

fn lookup_or_reserve<'a>(&'a self, key: &K) -> ObjectCacheResult<'a, V>

Looks up a key in the cache and may return a cached value for it. See ObjectCacheResult.

Source

fn is_cacheable(&self, key: &K) -> bool

Returns whether the key is cacheable. This is used by clients to avoid cloning keys and values when calling invalidate would do nothing.

Must be consistent with lookup_or_reserve returning NoCache.

Source

fn invalidate(&self, key: &K, value: Option<V>)

Removes key from cache if value is None, invalidates the results of placeholders that have not been resolved. When value is provided then the value may be inserted, and may replace an existing value.

Source

fn clear(&self)

Clears all entries from the cache.

Provided Methods§

Source

fn len(&self) -> usize

Returns the number of cached entries (for testing/diagnostics).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§