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
impl CacheBuilder
Sourcepub fn consistency_checker(
&mut self,
checker: impl Fn(&mut File, &mut File) -> Result<()> + Sync + Send + RefUnwindSafe + UnwindSafe + Sized + 'static,
) -> &mut Self
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.
Sourcepub fn byte_equality_checker(&mut self) -> &mut Self
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.
Sourcepub fn panicking_byte_equality_checker(&mut self) -> &mut Self
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.
Sourcepub fn clear_consistency_checker(&mut self) -> &mut Self
pub fn clear_consistency_checker(&mut self) -> &mut Self
Removes the consistency checker function, if any.
Sourcepub fn arc_consistency_checker(
&mut self,
checker: Option<Arc<dyn Fn(&mut File, &mut File) -> Result<()> + Sync + Send + RefUnwindSafe + UnwindSafe>>,
) -> &mut Self
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.
Sourcepub fn writer(
&mut self,
path: impl AsRef<Path>,
num_shards: usize,
total_capacity: usize,
) -> &mut Self
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.
Sourcepub fn plain_writer(
&mut self,
path: impl AsRef<Path>,
capacity: usize,
) -> &mut Self
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.
Sourcepub fn sharded_writer(
&mut self,
path: impl AsRef<Path>,
num_shards: usize,
total_capacity: usize,
) -> &mut Self
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.
Sourcepub fn auto_sync(&mut self, sync: bool) -> &mut Self
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.
Sourcepub fn reader(&mut self, path: impl AsRef<Path>, num_shards: usize) -> &mut Self
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.
Sourcepub fn plain_reader(&mut self, path: impl AsRef<Path>) -> &mut Self
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.
Sourcepub fn plain_readers(
&mut self,
paths: impl IntoIterator<Item = impl AsRef<Path>>,
) -> &mut Self
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.
Sourcepub fn sharded_reader(
&mut self,
path: impl AsRef<Path>,
num_shards: usize,
) -> &mut Self
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.