Engine

Trait Engine 

Source
pub trait Engine<K, V, P>:
    Send
    + Sync
    + 'static
    + Debug
    + Any{
    // Required methods
    fn device(&self) -> &Arc<dyn Device>;
    fn filter(&self, hash: u64, estimated_size: usize) -> StorageFilterResult;
    fn enqueue(&self, piece: PieceRef<K, V, P>, estimated_size: usize);
    fn load(&self, hash: u64) -> BoxFuture<'static, Result<Load<K, V, P>>>;
    fn delete(&self, hash: u64);
    fn may_contains(&self, hash: u64) -> bool;
    fn destroy(&self) -> BoxFuture<'static, Result<()>>;
    fn wait(&self) -> BoxFuture<'static, ()>;
    fn close(&self) -> BoxFuture<'static, Result<()>>;
}
Expand description

Disk cache engine trait.

Required Methods§

Source

fn device(&self) -> &Arc<dyn Device>

Get the device used by this disk cache engine.

Source

fn filter(&self, hash: u64, estimated_size: usize) -> StorageFilterResult

Return if the given key can be picked by the disk cache engine.

Source

fn enqueue(&self, piece: PieceRef<K, V, P>, estimated_size: usize)

Push a in-memory cache piece to the disk cache write queue.

Source

fn load(&self, hash: u64) -> BoxFuture<'static, Result<Load<K, V, P>>>

Load a cache entry from the disk cache.

load may return a false-positive result on entry key hash collision. It’s the caller’s responsibility to check if the returned key matches the given key.

Source

fn delete(&self, hash: u64)

Delete the cache entry with the given key from the disk cache.

Source

fn may_contains(&self, hash: u64) -> bool

Check if the disk cache contains a cached entry with the given key.

contains may return a false-positive result if there is a hash collision with the given key.

Source

fn destroy(&self) -> BoxFuture<'static, Result<()>>

Delete all cached entries of the disk cache.

Source

fn wait(&self) -> BoxFuture<'static, ()>

Wait for the ongoing flush and reclaim tasks to finish.

Source

fn close(&self) -> BoxFuture<'static, Result<()>>

Close the disk cache gracefully.

close will wait for all ongoing flush and reclaim tasks to finish.

Implementors§