Skip to main content

Cache

Trait Cache 

Source
pub trait Cache:
    Debug
    + Send
    + Sync
    + DynClone {
    // Required methods
    fn len(&self) -> usize;
    fn put(&self, key: &CacheKey, signed_packet: &SignedPacket);
    fn get(&self, key: &CacheKey) -> Option<SignedPacket>;

    // Provided methods
    fn capacity(&self) -> usize { ... }
    fn is_empty(&self) -> bool { ... }
    fn get_read_only(&self, key: &CacheKey) -> Option<SignedPacket> { ... }
}
Expand description

A trait for a SignedPackets cache for Pkarr Client.

Required Methods§

Source

fn len(&self) -> usize

Returns the number of SignedPackets in this cache.

Source

fn put(&self, key: &CacheKey, signed_packet: &SignedPacket)

Puts SignedPacket into cache.

Source

fn get(&self, key: &CacheKey) -> Option<SignedPacket>

Reads SignedPacket from cache, while moving it to the head of the LRU list.

Provided Methods§

Source

fn capacity(&self) -> usize

Returns the maximum capacity of SignedPackets allowed in this cache.

Source

fn is_empty(&self) -> bool

Returns true if this cache is empty.

Source

fn get_read_only(&self, key: &CacheKey) -> Option<SignedPacket>

Reads SignedPacket from cache, without changing the LRU list.

Used for internal reads that are not initiated by the user directly, like comparing an received signed packet with existing one.

Useful to implement differently from Cache::get, if you are implementing persistent cache where writes are slower than reads.

Otherwise it will just use Cache::get.

Implementors§