pub struct CacheManager { /* private fields */ }Expand description
Manages cache lifecycle: freshness check, rebuild, and fallback to TSJSON.
§Usage
use bones_core::cache::manager::CacheManager;
let mgr = CacheManager::new(".bones/events", ".bones/cache/events.bin");
let events = mgr.load_events().unwrap();Implementations§
Source§impl CacheManager
impl CacheManager
Sourcepub fn new(
events_dir: impl Into<PathBuf>,
cache_path: impl Into<PathBuf>,
) -> Self
pub fn new( events_dir: impl Into<PathBuf>, cache_path: impl Into<PathBuf>, ) -> Self
Create a new cache manager.
§Arguments
events_dir— Path to.bones/events/shard directory.cache_path— Path to.bones/cache/events.bin.
Sourcepub fn is_fresh(&self) -> Result<bool>
pub fn is_fresh(&self) -> Result<bool>
Check whether the cache file exists and is fresh.
Returns true if:
- The cache file exists and can be opened.
- The stored fingerprint matches the current shard fingerprint.
Returns false otherwise (missing, corrupt, stale, or on any error).
§Errors
Returns an error if computing the shard fingerprint fails.
Sourcepub fn load_events(&self) -> Result<LoadResult>
pub fn load_events(&self) -> Result<LoadResult>
Load events, preferring the binary cache when fresh.
- Compute a fingerprint over event shard files.
- If cache exists and fingerprint matches → decode from cache.
- Otherwise → parse TSJSON, then rebuild the cache in the foreground (so next call is fast). Cache rebuild failures are logged but do not cause the load to fail.
§Errors
Returns an error only if TSJSON parsing itself fails. Cache errors are handled by falling back to TSJSON.
Sourcepub fn rebuild(&self) -> Result<CacheStats>
pub fn rebuild(&self) -> Result<CacheStats>
Force a cache rebuild from TSJSON event shards.
Returns statistics about the rebuilt cache.
§Errors
Returns an error if shard replay, parsing, or cache writing fails.
Sourcepub fn events_dir(&self) -> &Path
pub fn events_dir(&self) -> &Path
Return the path to the events directory.
Sourcepub fn cache_path(&self) -> &Path
pub fn cache_path(&self) -> &Path
Return the path to the cache file.
Trait Implementations§
Source§impl Clone for CacheManager
impl Clone for CacheManager
Source§fn clone(&self) -> CacheManager
fn clone(&self) -> CacheManager
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 Freeze for CacheManager
impl RefUnwindSafe for CacheManager
impl Send for CacheManager
impl Sync for CacheManager
impl Unpin for CacheManager
impl UnsafeUnpin for CacheManager
impl UnwindSafe for CacheManager
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