Skip to main content

CacheablePredictor

Trait CacheablePredictor 

Source
pub trait CacheablePredictor {
    // Required methods
    fn cacheable_prediction(&self, key: &CacheKey) -> bool;
    fn mark_cacheable(&self, key: &CacheKey) -> bool;
    fn mark_uncacheable(
        &self,
        key: &CacheKey,
        reason: NoCacheReason,
    ) -> Option<bool>;

    // Provided method
    fn predicted_uncacheable_reason(
        &self,
        _key: &CacheKey,
    ) -> Option<NoCacheReason> { ... }
}
Expand description

The cache predictor trait.

This trait allows user defined predictor to replace Predictor.

Required Methods§

Source

fn cacheable_prediction(&self, key: &CacheKey) -> bool

Return true if likely cacheable, false if likely not.

Source

fn mark_cacheable(&self, key: &CacheKey) -> bool

Mark cacheable to allow next request to cache. Returns false if the key was already marked cacheable.

Source

fn mark_uncacheable( &self, key: &CacheKey, reason: NoCacheReason, ) -> Option<bool>

Mark uncacheable to actively bypass cache on the next request. May skip marking on certain NoCacheReasons. Returns None if we skipped marking uncacheable. Returns Some(false) if the key was already marked uncacheable.

Provided Methods§

Source

fn predicted_uncacheable_reason(&self, _key: &CacheKey) -> Option<NoCacheReason>

Return the NoCacheReason this key is currently remembered as uncacheable for.

Callers use this to report why a request bypassed the cache instead of inferring it. None means the key is not remembered as uncacheable, or the implementation does not track reasons, so callers must not assume anything about the previous response.

The default implementation returns None.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<const N_SHARDS: usize> CacheablePredictor for Predictor<N_SHARDS>