Skip to main content

BlobCache

Struct BlobCache 

Source
pub struct BlobCache { /* private fields */ }
Expand description

Stores immutable Dex blob payloads in a bounded local directory.

A cache is thread-safe. Reads and writes may run concurrently, while deletion and close coordinate with in-flight operations. Payloads survive process restarts; BlobCache::open recovers valid committed entries and removes interrupted writes.

§Examples

use dex_blob_cache::{BlobCache, BlobCacheConfig};

let config = BlobCacheConfig::new("/tmp/dex-blobs", 64 * 1024 * 1024, 0)?;
let cache = BlobCache::open(config)?;
assert!(cache.put("orders/123", b"payload")?);
assert_eq!(cache.get("orders/123")?, Some(b"payload".to_vec()));
cache.close()?;

Implementations§

Source§

impl BlobCache

Source

pub fn open(config: BlobCacheConfig) -> Result<Self, BlobCacheError>

Opens a cache and recovers its committed entries.

config supplies the owned directory, byte budget, and admission-policy sizing. The call creates the directory when needed and returns only after recovery completes.

§Errors

Returns BlobCacheError when the directory cannot be prepared, recovery finds an unrecoverable storage failure, or the admission policy cannot be initialized.

Source

pub fn get(&self, blob_id: &str) -> Result<Option<Vec<u8>>, BlobCacheError>

Reads one payload and records an admission-policy access.

Returns Ok(Some(payload)) for a valid entry and Ok(None) when the ID is absent or its file disappeared or became corrupt. Corrupt entries are invalidated before returning.

§Errors

Returns BlobCacheError::InvalidBlob for an invalid ID, BlobCacheError::Closed after close, or a storage/policy error that cannot be treated as a cache miss.

Source

pub fn put(&self, blob_id: &str, payload: &[u8]) -> Result<bool, BlobCacheError>

Attempts to admit an immutable payload under blob_id.

Returns Ok(true) when the payload is committed or the identical payload already exists. Returns Ok(false) when the payload exceeds the byte budget or the policy rejects it. Reusing an ID for different bytes is an error.

§Errors

Returns BlobCacheError for invalid IDs, content mismatches, closed lifecycle, or failed filesystem and policy operations.

Source

pub fn delete(&self, blob_id: &str) -> Result<(), BlobCacheError>

Deletes one blob if present.

Missing IDs succeed, making deletion idempotent.

§Errors

Returns BlobCacheError for an invalid ID, a closed cache, or a failed storage/policy operation.

Source

pub fn delete_all(&self) -> Result<(), BlobCacheError>

Removes every cache entry while keeping the cache open.

The call excludes concurrent cache operations until both policy and disk state are cleared.

§Errors

Returns BlobCacheError::Closed after close or a reconciliation/storage failure when the cache cannot fully purge its state.

Source

pub fn close(&self) -> Result<(), BlobCacheError>

Releases policy resources and rejects future operations.

Close is idempotent and preserves committed files for the next BlobCache::open.

§Errors

Returns a cleanup error after closing when a previously deferred file removal still fails.

Trait Implementations§

Source§

impl Drop for BlobCache

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more