pub enum CacheStrategy {
Fresh,
Refresh,
Invalidate,
Bypass,
}Expand description
Strategy enum controlling cache fetch/invalidation behavior.
Replaces boolean flags with explicit, type-safe options.
§Examples
use cache_kit::strategy::CacheStrategy;
// Use cache only
let _strategy = CacheStrategy::Fresh;
// Try cache, fallback to database
let _strategy = CacheStrategy::Refresh;
// Clear cache and refresh from database
let _strategy = CacheStrategy::Invalidate;
// Skip cache entirely
let _strategy = CacheStrategy::Bypass;Variants§
Fresh
Fresh: Try cache only, no fallback to database.
Use when: You know data should be in cache, and miss is an error condition.
Flow:
- Check cache
- If hit: return cached value
- If miss: return None (don’t hit database)
Refresh
Refresh: Try cache first, fallback to database on miss.
Use when: Default behavior, prefer cache but ensure data availability.
Flow:
- Check cache
- If hit: return cached value
- If miss: fetch from database
- Store in cache
- Return value
Invalidate
Invalidate: Mark cache as invalid and refresh from database.
Use when: You know cache is stale and need fresh data. Typical use: After update/mutation operations.
Flow:
- Delete from cache
- Fetch from database
- Store in cache
- Return value
Bypass
Bypass: Ignore cache entirely, always fetch from database.
Use when: Cache is temporarily disabled or for specific read-through scenarios.
Flow:
- Fetch from database
- Store in cache (for others)
- Return value
Trait Implementations§
Source§impl Clone for CacheStrategy
impl Clone for CacheStrategy
Source§fn clone(&self) -> CacheStrategy
fn clone(&self) -> CacheStrategy
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 moreSource§impl Debug for CacheStrategy
impl Debug for CacheStrategy
Source§impl Default for CacheStrategy
impl Default for CacheStrategy
Source§fn default() -> CacheStrategy
fn default() -> CacheStrategy
Returns the “default value” for a type. Read more
Source§impl Display for CacheStrategy
impl Display for CacheStrategy
Source§impl PartialEq for CacheStrategy
impl PartialEq for CacheStrategy
impl Eq for CacheStrategy
impl StructuralPartialEq for CacheStrategy
Auto Trait Implementations§
impl Freeze for CacheStrategy
impl RefUnwindSafe for CacheStrategy
impl Send for CacheStrategy
impl Sync for CacheStrategy
impl Unpin for CacheStrategy
impl UnwindSafe for CacheStrategy
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