Skip to main content

SharedCache

Struct SharedCache 

Source
pub struct SharedCache(/* private fields */);
Expand description

A cache several Engines share, so a process serving many APKs keeps one memory budget (the LRU is keyed by APK) and one disk-writer thread. Engines attached with Engine::with_shared_cache leave queued disk writes alone when dropped; dropping the SharedCache flushes them and stops queueing (as dropping a private engine does).

Implementations§

Source§

impl SharedCache

Source

pub fn fit_resident(&self, engines: &[&Engine]) -> Vec<usize>

Of engines, most recently used first, the indexes of those to close so that what the rest hold fits in half the memory budget; what stays is reserved in the budget. The most recent engine stays whatever its size; without a memory cache every engine stays.

Sizing waits for an engine building its class graph, so callers do not hold their own engine registry’s lock across this call.

Source

pub fn fit_resident_bytes(&self, sizes: &[usize]) -> Vec<usize>

SharedCache::fit_resident by what each open program holds outside the cache, for a host whose programs are not all Engines (another format’s engines share the budget).

Source

pub fn resident_share(&self) -> usize

The bytes open programs may hold outside the cache: half the memory budget.

Source§

impl SharedCache

Source

pub fn new( config: CacheConfig, logger: impl Fn(&str) + Send + Sync + 'static, ) -> SharedCache

Build the cache Engine::with_cache would; warnings (an unusable disk cache directory) go to logger.

Source

pub fn memory_bytes(&self) -> usize

Bytes currently held by the shared in-memory cache.

Source

pub fn memory_capacity(&self) -> usize

Budget of the shared in-memory cache (0 when it is disabled).

Source

pub fn memory_reserved(&self) -> usize

Bytes counted against the memory budget besides the cache’s entries (SharedCache::set_reserved).

Source

pub fn set_reserved(&self, bytes: usize)

Count bytes the host holds outside the cache (the class graphs and resource tables of its engines, Engine::resident_bytes) against the memory budget: the cache evicts entries to make room for them.

Source

pub fn flush_writes(&self)

Block until every queued disk-cache write has landed.

Trait Implementations§

Source§

impl Drop for SharedCache

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