Skip to main content

CacheKeyLock

Trait CacheKeyLock 

Source
pub trait CacheKeyLock {
    // Required methods
    fn lock(&self, key: &CacheKey, stale_writer: bool) -> Locked;
    fn release(&self, key: &CacheKey, permit: WritePermit, reason: LockStatus);

    // Provided methods
    fn trace_lock_wait(
        &self,
        span: &mut Span,
        _read_lock: &ReadLock,
        lock_status: LockStatus,
    ) { ... }
    fn custom_lock_status(&self, _custom_no_cache: &'static str) -> LockStatus { ... }
}

Required Methods§

Source

fn lock(&self, key: &CacheKey, stale_writer: bool) -> Locked

Try to lock a cache fetch

If stale_writer is true, this fetch is to revalidate an asset already in cache. Else this fetch was a cache miss (i.e. not found via lookup, or force missed).

Users should call after a cache miss before fetching the asset. The returned Locked will tell the caller either to fetch or wait.

Source

fn release(&self, key: &CacheKey, permit: WritePermit, reason: LockStatus)

Release a lock for the given key

When the write lock is dropped without being released, the read lock holders will consider it to be failed so that they will compete for the write lock again.

Provided Methods§

Source

fn trace_lock_wait( &self, span: &mut Span, _read_lock: &ReadLock, lock_status: LockStatus, )

Set tags on a trace span for the cache lock wait.

Source

fn custom_lock_status(&self, _custom_no_cache: &'static str) -> LockStatus

Set a lock status for a custom NoCacheReason.

Implementors§