pub struct Cache { /* private fields */ }Expand description
Cache, in which blocks or blobs are cached in-memory after being retrieved from disk
This speeds up consecutive queries to nearby data, improving read performance for hot data.
§Examples
Sharing cache between multiple trees
// Provide 64 MB of cache capacity
let cache = Arc::new(Cache::with_capacity_bytes(64 * 1_000 * 1_000));
let tree1 = Config::new(folder, Default::default(), Default::default()).use_cache(cache.clone()).open()?;
let tree2 = Config::new(folder, Default::default(), Default::default()).use_cache(cache.clone()).open()?;Implementations§
Source§impl Cache
impl Cache
Sourcepub fn with_capacity_bytes(bytes: u64) -> Self
pub fn with_capacity_bytes(bytes: u64) -> Self
Creates a new block cache with roughly n bytes of capacity.
Sourcepub fn with_row_cache(self, enabled: bool) -> Self
pub fn with_row_cache(self, enabled: bool) -> Self
Enables or disables the row cache (decoded point-read results), returning the cache for builder-style configuration. On by default; rows share the block cache’s byte capacity.
Sourcepub fn row_cache_enabled(&self) -> bool
pub fn row_cache_enabled(&self) -> bool
Whether the row cache is enabled (see Cache::with_row_cache).
Sourcepub fn with_metadata_priority(self, enabled: bool) -> Self
pub fn with_metadata_priority(self, enabled: bool) -> Self
Enables or disables high-priority pinning of index / filter /
range-tombstone blocks (see Cache::metadata_priority field docs),
returning the cache for builder-style configuration. On by default.
Sourcepub fn metadata_priority(&self) -> bool
pub fn metadata_priority(&self) -> bool
Whether metadata-block priority pinning is enabled (see
Cache::with_metadata_priority).
Sourcepub fn with_load_coalescing_after(self, after: Duration) -> Self
pub fn with_load_coalescing_after(self, after: Duration) -> Self
Sets how long cold loads must take before readers that miss the same block, blob or column directory at once share one read and decode instead of each doing it, returning the cache for builder-style configuration.
The cache times a sample of its cold loads. While they finish quicker
than after (blocks served from the page cache, with cores to spare),
a reader loads on its own: waiting for another reader’s load would
cost it more than its own. Once loads take longer (slow or remote
storage, or cores saturated), concurrent misses of one object wait for
a single load. Duration::ZERO shares every load; Duration::MAX
none. Without the std feature loads are not timed, so only
Duration::ZERO shares there.
§Examples
use core::time::Duration;
use lsm_tree::Cache;
let cache = Cache::with_capacity_bytes(64 << 20)
.with_load_coalescing_after(Duration::from_micros(50));
assert_eq!(cache.load_coalescing_after(), Duration::from_micros(50));Sourcepub fn load_coalescing_after(&self) -> Duration
pub fn load_coalescing_after(&self) -> Duration
How long cold loads must take before concurrent misses share them
(see Cache::with_load_coalescing_after).
Auto Trait Implementations§
impl !RefUnwindSafe for Cache
impl !UnwindSafe for Cache
impl Freeze for Cache
impl Send for Cache
impl Sync for Cache
impl Unpin for Cache
impl UnsafeUnpin for Cache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more