pub struct LookupCache<K, V> { /* private fields */ }Expand description
Cache for frequently accessed lookups.
This provides a simple LRU-like cache for domain and predicate lookups to avoid repeated hash table accesses.
§Example
use tensorlogic_adapters::LookupCache;
let mut cache = LookupCache::new(100);
cache.insert("Person".to_string(), 42);
assert_eq!(cache.get(&"Person".to_string()), Some(&42));Implementations§
Source§impl<K: Clone + Eq + Hash, V: Clone> LookupCache<K, V>
impl<K: Clone + Eq + Hash, V: Clone> LookupCache<K, V>
Sourcepub fn insert(&mut self, key: K, value: V)
pub fn insert(&mut self, key: K, value: V)
Insert a key-value pair into the cache.
If the cache is at capacity, removes the least recently used item.
Sourcepub fn get(&mut self, key: &K) -> Option<&V>
pub fn get(&mut self, key: &K) -> Option<&V>
Get a value from the cache, updating access count.
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Get cache hit statistics.
Trait Implementations§
Source§impl<K: Clone, V: Clone> Clone for LookupCache<K, V>
impl<K: Clone, V: Clone> Clone for LookupCache<K, V>
Source§fn clone(&self) -> LookupCache<K, V>
fn clone(&self) -> LookupCache<K, V>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<K, V> Freeze for LookupCache<K, V>
impl<K, V> RefUnwindSafe for LookupCache<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for LookupCache<K, V>
impl<K, V> Sync for LookupCache<K, V>
impl<K, V> Unpin for LookupCache<K, V>
impl<K, V> UnwindSafe for LookupCache<K, V>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more