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§
Sourcepub fn fit_resident(&self, engines: &[&Engine]) -> Vec<usize>
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.
Sourcepub fn fit_resident_bytes(&self, sizes: &[usize]) -> Vec<usize>
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).
The bytes open programs may hold outside the cache: half the memory budget.
Sourcepub fn new(
config: CacheConfig,
logger: impl Fn(&str) + Send + Sync + 'static,
) -> SharedCache
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.
Sourcepub fn memory_bytes(&self) -> usize
pub fn memory_bytes(&self) -> usize
Bytes currently held by the shared in-memory cache.
Sourcepub fn memory_capacity(&self) -> usize
pub fn memory_capacity(&self) -> usize
Budget of the shared in-memory cache (0 when it is disabled).
Sourcepub fn memory_reserved(&self) -> usize
pub fn memory_reserved(&self) -> usize
Bytes counted against the memory budget besides the cache’s entries
(SharedCache::set_reserved).
Sourcepub fn set_reserved(&self, bytes: usize)
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.
Sourcepub fn flush_writes(&self)
pub fn flush_writes(&self)
Block until every queued disk-cache write has landed.