ContentStore

Trait ContentStore 

Source
pub trait ContentStore:
    Send
    + Sync
    + 'static {
    // Required methods
    fn get(
        &self,
        interest: &Interest,
    ) -> impl Future<Output = Option<CsEntry>> + Send;
    fn insert(
        &self,
        data: Bytes,
        name: Arc<Name>,
        meta: CsMeta,
    ) -> impl Future<Output = InsertResult> + Send;
    fn evict(&self, name: &Name) -> impl Future<Output = bool> + Send;
    fn capacity(&self) -> CsCapacity;

    // Provided methods
    fn len(&self) -> usize { ... }
    fn is_empty(&self) -> bool { ... }
    fn current_bytes(&self) -> usize { ... }
    fn set_capacity(&self, _max_bytes: usize) { ... }
    fn variant_name(&self) -> &str { ... }
    fn evict_prefix(
        &self,
        _prefix: &Name,
        _limit: Option<usize>,
    ) -> impl Future<Output = usize> + Send { ... }
    fn stats(&self) -> CsStats { ... }
}
Expand description

The ContentStore trait.

All methods are async to allow persistent (disk-backed) implementations. In-memory implementations complete synchronously but Tokio will inline the no-op future at zero cost.

Required Methods§

Source

fn get( &self, interest: &Interest, ) -> impl Future<Output = Option<CsEntry>> + Send

Look up a Data packet matching interest. Honours MustBeFresh and CanBePrefix selectors.

Source

fn insert( &self, data: Bytes, name: Arc<Name>, meta: CsMeta, ) -> impl Future<Output = InsertResult> + Send

Store a Data packet. May evict least-recently-used entries to make room.

Source

fn evict(&self, name: &Name) -> impl Future<Output = bool> + Send

Explicitly evict the entry for name.

Source

fn capacity(&self) -> CsCapacity

Current capacity configuration.

Provided Methods§

Source

fn len(&self) -> usize

Number of entries currently cached.

Source

fn is_empty(&self) -> bool

Returns true if the content store contains no entries.

Source

fn current_bytes(&self) -> usize

Total bytes currently used.

Source

fn set_capacity(&self, _max_bytes: usize)

Update the maximum byte capacity at runtime.

Source

fn variant_name(&self) -> &str

Human-readable name of this CS implementation (e.g. “lru”, “sharded-lru”).

Source

fn evict_prefix( &self, _prefix: &Name, _limit: Option<usize>, ) -> impl Future<Output = usize> + Send

Evict all entries matching prefix, up to limit entries (None = unlimited). Returns the number of entries evicted.

Source

fn stats(&self) -> CsStats

Snapshot of hit/miss/insert/eviction counters.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§