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§
Sourcefn len(&self) -> usize
fn len(&self) -> usize
Returns the number of SignedPackets in this cache.
Sourcefn put(&self, key: &CacheKey, signed_packet: &SignedPacket)
fn put(&self, key: &CacheKey, signed_packet: &SignedPacket)
Puts SignedPacket into cache.
Sourcefn get(&self, key: &CacheKey) -> Option<SignedPacket>
fn get(&self, key: &CacheKey) -> Option<SignedPacket>
Reads SignedPacket from cache, while moving it to the head of the LRU list.
Provided Methods§
Sourcefn capacity(&self) -> usize
fn capacity(&self) -> usize
Returns the maximum capacity of SignedPackets allowed in this cache.
Sourcefn get_read_only(&self, key: &CacheKey) -> Option<SignedPacket>
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.