[go: up one dir, main page]

cached 0.2.2

Simple function caching/memoization
Documentation
use std::hash::Hash;
use std::cmp::Eq;

pub mod macros;
pub mod stores;

pub use stores::*;


/// Blank `marker` function to help enforce the `cached::Cached` trait on any
/// explicitly specified `Cache` types
pub fn enforce_cached_impl<K: Hash + Eq, V, T: Cached<K, V>>(_: &::std::sync::MutexGuard<T>) {}


pub trait Cached<K, V> {
    fn cache_get(&mut self, k: &K) -> Option<&V>;
    fn cache_set(&mut self, k: K, v: V);
    fn cache_size(&self) -> usize;
    fn cache_hits(&self) -> Option<u32> { None }
    fn cache_misses(&self) -> Option<u32> { None }
    fn cache_capacity(&self) -> Option<usize> { None }
    fn cache_lifespan(&self) -> Option<u64> { None }
}