Skip to main content

DiskCache

Struct DiskCache 

Source
pub struct DiskCache<'directory, 'buffer> { /* private fields */ }
Expand description

One bounded resident buffer backed by immutable cache files. Each get reloads its file so eviction and corrupt entries remain visible. The core selected writer validates every returned pack before output. Oversized files fail before reading into the buffer; no pack-sized allocation or mapping is performed here. A host may open independent instances for concurrent readers.

Implementations§

Source§

impl DiskCache<'_, '_>

Source

pub fn try_lease(&self, key: Key) -> Result<Option<Lease>>

Attempt one nonblocking exclusive lock for a selected key. None means the cache is disabled or another cooperative producer holds the lock. After acquisition, recheck the cache before generating a pack: another producer may have completed while this request waited to retry. Authorization and selection remain mandatory before every lookup.

Guards own independent close-on-exec descriptors and do not borrow the backend, so the host can call the selected writer while holding one. Eviction affects .pack files only and never removes the lock identity.

Source§

impl<'directory, 'buffer> DiskCache<'directory, 'buffer>

Source

pub fn new( directory: BorrowedFd<'directory>, buffer: &'buffer mut [u8], nonce: [u8; 16], ) -> Self

Supply a trusted directory descriptor, fixed resident bytes, and a host-chosen nonce unique among concurrent producers in that directory. Exclusive staging-file creation safely rejects nonce/name collisions.

Source

pub fn set_enabled(&mut self, enabled: bool)

Source

pub fn statistics(&self) -> Statistics

Source

pub fn evict(&mut self, key: Key) -> Result<bool>

Unlink only this exact key. Readers that already copied a verified pack remain independent. Missing entries return false. No directory scan or automatic eviction of other authorization namespaces is performed.

Trait Implementations§

Source§

impl PackCache for DiskCache<'_, '_>

Source§

fn get(&mut self, key: Key) -> Result<Option<&[u8]>>

Source§

fn put(&mut self, key: Key, bytes: &[u8]) -> Result<()>

Auto Trait Implementations§

§

impl<'directory, 'buffer> !UnwindSafe for DiskCache<'directory, 'buffer>

§

impl<'directory, 'buffer> Freeze for DiskCache<'directory, 'buffer>

§

impl<'directory, 'buffer> RefUnwindSafe for DiskCache<'directory, 'buffer>

§

impl<'directory, 'buffer> Send for DiskCache<'directory, 'buffer>

§

impl<'directory, 'buffer> Sync for DiskCache<'directory, 'buffer>

§

impl<'directory, 'buffer> Unpin for DiskCache<'directory, 'buffer>

§

impl<'directory, 'buffer> UnsafeUnpin for DiskCache<'directory, 'buffer>

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, 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.