pub struct CacheBuilder { /* private fields */ }
Expand description

Construct a Cache with this builder. The resulting cache will always first access its write-side cache (if defined), and, on misses, will attempt to service Cache::get and Cache::touch calls by iterating over the read-only caches.

Implementations§

source§

impl CacheBuilder

source

pub fn new() -> Self

Returns a fresh empty builder.

source

pub fn consistency_checker( &mut self, checker: impl Fn(&mut File, &mut File) -> Result<()> + Sync + Send + RefUnwindSafe + UnwindSafe + Sized + 'static ) -> &mut Self

Sets the consistency checker function: when the function is provided, the ReadOnlyCache will keep searching after the first cache hit, and compare subsequent hits with the first one by calling checker. The checker function should return Ok(()) if the two files are compatible (identical), and Err otherwise.

Kismet will propagate the error on mismatch.

source

pub fn byte_equality_checker(&mut self) -> &mut Self

Sets the consistency checker function to crate::byte_equality_checker: the contents of all cache hits must be bytewise identical, without considering any metadata.

source

pub fn panicking_byte_equality_checker(&mut self) -> &mut Self

Sets the consistency checker function to crate::panicking_byte_equality_checker: the contents of all cache hits must be bytewise identical, without considering any metadata, and the call will panic on mismatch.

source

pub fn clear_consistency_checker(&mut self) -> &mut Self

Removes the consistency checker function, if any.

source

pub fn arc_consistency_checker( &mut self, checker: Option<Arc<dyn Fn(&mut File, &mut File) -> Result<()> + Sync + Send + RefUnwindSafe + UnwindSafe>> ) -> &mut Self

Sets the consistency checker function. None clears the checker function. See CacheBuilder::consistency_checker.

source

pub fn writer( &mut self, path: impl AsRef<Path>, num_shards: usize, total_capacity: usize ) -> &mut Self

Sets the read-write cache directory to path.

The read-write cache will be a plain cache directory if num_shards <= 1, and a sharded directory otherwise.

source

pub fn plain_writer( &mut self, path: impl AsRef<Path>, capacity: usize ) -> &mut Self

Sets the read-write cache directory to a plain directory at path, with a target file count of up to capacity.

source

pub fn sharded_writer( &mut self, path: impl AsRef<Path>, num_shards: usize, total_capacity: usize ) -> &mut Self

Sets the read-write cache directory to a sharded directory at path, with num_shards subdirectories and a target file count of up to capacity for the entire cache.

source

pub fn auto_sync(&mut self, sync: bool) -> &mut Self

Sets whether files published read-write cache will be automatically flushed to disk with File::sync_all before sending them to the cache directory.

Defaults to true, for safety. Even when auto_sync is enabled, Kismet does not fsync cache directories; after a kernel or hardware crash, caches may partially revert to an older state, but should not contain incomplete files.

An application may want to disable auto_sync because it already synchronises files, or because the cache directories do not survive crashes: they might be erased after each boot, e.g., via tmpfiles.d, or tagged with a boot id.

source

pub fn reader(&mut self, path: impl AsRef<Path>, num_shards: usize) -> &mut Self

Adds a new read-only cache directory at path to the end of the cache builder’s search list.

Adds a plain cache directory if num_shards <= 1, and a sharded directory otherwise.

source

pub fn plain_reader(&mut self, path: impl AsRef<Path>) -> &mut Self

Adds a new plain (unsharded) read-only cache directory at path to the end of the cache builder’s search list.

source

pub fn plain_readers( &mut self, paths: impl IntoIterator<Item = impl AsRef<Path>> ) -> &mut Self

Adds a new plain cache read-only directory for each path in paths. The caches are appended in order to the end of the cache builder’s search list.

source

pub fn sharded_reader( &mut self, path: impl AsRef<Path>, num_shards: usize ) -> &mut Self

Adds a new sharded read-only cache directory at path to the end of the cache builder’s search list.

source

pub fn take(&mut self) -> Self

Returns the contents of self as a fresh value; self is reset to the default empty builder state. This makes it possible to declare simple configurations in a single expression, with .take().build().

source

pub fn build(self) -> Cache

Returns a fresh Cache for the builder’s write cache and additional search list of read-only cache directories.

Trait Implementations§

source§

impl Debug for CacheBuilder

source§

fn fmt(&self, __f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for CacheBuilder

source§

fn default() -> CacheBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V