pub struct Cache<const G: usize, const L: usize> { /* private fields */ }Expand description
A cache storage structure.
- G: the number of cache groups
- L: the number of cache lines in each group
load a Cacheable into memory:
- cache hit: update LRU
- cache empty: load Cacheable into the cache
- cache group full: evict the least recently used Cacheable
Cacheable::load()failed: IoError
The cache refreshes itself by the LRU algorithm.
If CacheMut is dereferenced, cache will be marked dirty,
Cacheable::store() will be called when:
- The
Cacheis dropped. - The
CacheLineholding the dirtyCacheableis evicted.
Implementations§
source§impl<const G: usize, const L: usize> Cache<G, L>
impl<const G: usize, const L: usize> Cache<G, L>
sourcepub fn get<T: Cacheable + Default>(&self) -> CacheResult<CacheRef<'_, T>>
pub fn get<T: Cacheable + Default>(&self) -> CacheResult<CacheRef<'_, T>>
Retrieve a Cacheable from the cache. Use Default if Cacheable::load() failed.
At most 63 CacheRefs for each Cacheable type can be retrieved at the same time.
- If the cache hit, return a
CacheRef. - CacheError::Busy: cache miss, the CacheLine chosen to evict is being used.
- CacheError::Locked: cache hit, but the CacheLine for T is being written.
sourcepub fn get_mut<T: Cacheable + Default>(&self) -> CacheResult<CacheMut<'_, T>>
pub fn get_mut<T: Cacheable + Default>(&self) -> CacheResult<CacheMut<'_, T>>
Retrieve a mut Cacheable from the cache.
- If the cache hit, return a
CacheMut. Use Default ifCacheable::load()failed. - CacheError::Busy: cache miss, the CacheLine chosen to evict is being used.
- CacheError::Locked: cache hit, but the CacheLine for T is being read or written.
Trait Implementations§
Auto Trait Implementations§
impl<const G: usize, const L: usize> Freeze for Cache<G, L>
impl<const G: usize, const L: usize> !RefUnwindSafe for Cache<G, L>
impl<const G: usize, const L: usize> Send for Cache<G, L>
impl<const G: usize, const L: usize> Sync for Cache<G, L>
impl<const G: usize, const L: usize> Unpin for Cache<G, L>
impl<const G: usize, const L: usize> !UnwindSafe for Cache<G, L>
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)