pub struct FarmerCache { /* private fields */ }Expand description
Farmer cache that aggregates different kinds of caches of multiple disks.
Pieces in PieceCache are stored based on capacity and proximity of piece index to farmer’s
network identity. If capacity is not enough to store all pieces in cache then pieces that are
further from network identity will be evicted, this is helpful for quick retrieval of pieces
from DSN as well as plotting purposes.
PlotCache is used as a supplementary cache and is primarily helpful for smaller farmers
where piece cache is not enough to store all the pieces on the network, while there is a lot of
space in the plot that is not used by sectors yet and can be leverage as extra caching space.
Implementations§
Source§impl FarmerCache
impl FarmerCache
Sourcepub fn new<NC>(
node_client: NC,
peer_id: PeerId,
registry: Option<&mut Registry>,
) -> (Self, FarmerCacheWorker<NC>)where
NC: NodeClient,
pub fn new<NC>(
node_client: NC,
peer_id: PeerId,
registry: Option<&mut Registry>,
) -> (Self, FarmerCacheWorker<NC>)where
NC: NodeClient,
Create new piece cache instance and corresponding worker.
NOTE: Returned future is async, but does blocking operations and should be running in dedicated thread.
Sourcepub async fn get_piece<Key>(&self, key: Key) -> Option<Piece>where
RecordKey: From<Key>,
pub async fn get_piece<Key>(&self, key: Key) -> Option<Piece>where
RecordKey: From<Key>,
Get piece from cache
Sourcepub async fn get_pieces<'a, PieceIndices>(
&'a self,
piece_indices: PieceIndices,
) -> impl Stream<Item = (PieceIndex, Option<Piece>)> + Send + Unpin + 'a
pub async fn get_pieces<'a, PieceIndices>( &'a self, piece_indices: PieceIndices, ) -> impl Stream<Item = (PieceIndex, Option<Piece>)> + Send + Unpin + 'a
Get pieces from cache.
Number of elements in returned stream is the same as number of unique piece_indices.
Sourcepub async fn has_pieces(
&self,
piece_indices: Vec<PieceIndex>,
) -> Vec<PieceIndex>
pub async fn has_pieces( &self, piece_indices: Vec<PieceIndex>, ) -> Vec<PieceIndex>
Returns a filtered list of pieces that were found in farmer cache, order is not guaranteed
Sourcepub async fn find_piece(
&self,
piece_index: PieceIndex,
) -> Option<(PieceCacheId, PieceCacheOffset)>
pub async fn find_piece( &self, piece_index: PieceIndex, ) -> Option<(PieceCacheId, PieceCacheOffset)>
Find piece in cache and return its retrieval details
Sourcepub async fn find_pieces<PieceIndices>(
&self,
piece_indices: PieceIndices,
) -> Vec<(PieceIndex, PieceCacheId, PieceCacheOffset)>where
PieceIndices: IntoIterator<Item = PieceIndex>,
pub async fn find_pieces<PieceIndices>(
&self,
piece_indices: PieceIndices,
) -> Vec<(PieceIndex, PieceCacheId, PieceCacheOffset)>where
PieceIndices: IntoIterator<Item = PieceIndex>,
Find pieces in cache and return their retrieval details
Sourcepub async fn maybe_store_additional_piece(
&self,
piece_index: PieceIndex,
piece: &Piece,
) -> bool
pub async fn maybe_store_additional_piece( &self, piece_index: PieceIndex, piece: &Piece, ) -> bool
Try to store a piece in additional downloaded pieces, if there is space for it.
Returns true if the piece was added to this cache, and false if it was already stored,
or there was no space.
Sourcepub async fn replace_backing_caches(
&self,
new_piece_caches: Vec<Arc<dyn PieceCache>>,
new_plot_caches: Vec<Arc<dyn PlotCache>>,
)
pub async fn replace_backing_caches( &self, new_piece_caches: Vec<Arc<dyn PieceCache>>, new_plot_caches: Vec<Arc<dyn PlotCache>>, )
Initialize replacement of backing caches
Trait Implementations§
Source§impl Clone for FarmerCache
impl Clone for FarmerCache
Source§fn clone(&self) -> FarmerCache
fn clone(&self) -> FarmerCache
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FarmerCache
impl Debug for FarmerCache
Source§impl From<FarmerCache> for FarmerCaches
impl From<FarmerCache> for FarmerCaches
Source§fn from(cache: FarmerCache) -> Self
fn from(cache: FarmerCache) -> Self
Auto Trait Implementations§
impl Freeze for FarmerCache
impl !RefUnwindSafe for FarmerCache
impl Send for FarmerCache
impl Sync for FarmerCache
impl Unpin for FarmerCache
impl !UnwindSafe for FarmerCache
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more