Skip to main content

Cache

Trait Cache 

Source
pub trait Cache {
    // Required methods
    fn get_file(
        &self,
        key: &str,
        fallback: Fallback,
    ) -> Result<PathBuf, FileCacheError>;
    fn get_with_cancellation(
        &self,
        key: &str,
        fallback: Fallback,
        cancelled: bool,
    ) -> Result<Vec<u8>, FileCacheError>;

    // Provided method
    fn get(
        &self,
        key: &str,
        fallback: Fallback,
    ) -> Result<Vec<u8>, FileCacheError> { ... }
}
Expand description

Ported from the Cache interface.

Go’s Get takes a context.Context and checks ctx.Err() before calling the fallback, so an already-cancelled context short-circuits without ever running it (TestGet_ContextCancelled). This port has no ambient context type to thread through (see the module docs), so get_with_cancellation takes that one bit of ctx.Err() state as an explicit cancelled: bool parameter instead – the same “inject instead of read/carry ambient state” pattern used elsewhere in this crate (apply_sudo_with, has_gitlab_zoom_config, is_enabled_with). get is a default method for callers that don’t need cancellation at all; it always passes cancelled = false.

Required Methods§

Source

fn get_file( &self, key: &str, fallback: Fallback, ) -> Result<PathBuf, FileCacheError>

Source

fn get_with_cancellation( &self, key: &str, fallback: Fallback, cancelled: bool, ) -> Result<Vec<u8>, FileCacheError>

Provided Methods§

Source

fn get(&self, key: &str, fallback: Fallback) -> Result<Vec<u8>, FileCacheError>

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§