pub struct LastValueCache { /* private fields */ }Expand description
Last Value Cache — stores the most recent point per series.
§Thread Safety
Uses DashMap for lock-free concurrent reads and sharded writes.
Multiple threads can read and update the cache simultaneously.
§Memory
Memory usage scales linearly with the number of unique series.
Each entry stores one Point (typically 100-500 bytes).
§LRU Eviction
An optional max_entries cap prevents unbounded memory growth in
high-cardinality workloads. When full, the least recently used
entries are evicted in O(1) time using a HashMap-backed
doubly-linked list (replaces an O(N)
VecDeque::retain approach).
Implementations§
Source§impl LastValueCache
impl LastValueCache
Sourcepub fn with_max_entries(max: usize) -> Self
pub fn with_max_entries(max: usize) -> Self
Create an LVC with a maximum number of entries.
When full, the least recently used (LRU) entry is evicted to make room for the new one. Eviction is O(1).
Sourcepub fn with_capacity(n: usize) -> Self
pub fn with_capacity(n: usize) -> Self
Create an LVC with pre-allocated capacity for n series.
Sourcepub fn update(&self, point: &Point)
pub fn update(&self, point: &Point)
Update the cache with a new point. Only overwrites if the new point has a timestamp ≥ the existing cached point.
When max_entries > 0, the key is moved to the most-recently-used
position in O(1) time. If the cache is full and the key is new,
the least-recently-used entry is evicted — also O(1).
Sourcepub fn get(
&self,
measurement: &str,
tags: &BTreeMap<String, String>,
) -> Option<Point>
pub fn get( &self, measurement: &str, tags: &BTreeMap<String, String>, ) -> Option<Point>
Look up the most recent point for a series.
Returns None if the series has never been written to, or has
been evicted.
Sourcepub fn get_by_key(&self, key: &SeriesKey) -> Option<Point>
pub fn get_by_key(&self, key: &SeriesKey) -> Option<Point>
Look up by SeriesKey.
Sourcepub fn evict(&self, measurement: &str, tags: &BTreeMap<String, String>)
pub fn evict(&self, measurement: &str, tags: &BTreeMap<String, String>)
Remove a series from the cache.
Sourcepub fn evict_by_key(&self, key: &SeriesKey)
pub fn evict_by_key(&self, key: &SeriesKey)
Remove a series by its SeriesKey.
Sourcepub fn retain_series(&self, keep: impl Fn(&str) -> bool)
pub fn retain_series(&self, keep: impl Fn(&str) -> bool)
Keep only the series keep accepts, by canonical form.
The LVC is a copy of the newest row of every series, and a copy is not an answer: once retention has dropped a series’ data the raw query returns nothing while the cache kept returning its last reading — a device offline for longer than the retention window went on reporting a “current” value for ever. It is also how the cache stays bounded on a long-lived deployment: the live series set is bounded by retention, and without this the cache was not.
Called by the cardinality repair, against the budget it just rebuilt — as a predicate rather than a materialised set, so pruning the cache does not cost a copy of every live series.
Sourcepub fn evict_measurement(&self, measurement: &str)
pub fn evict_measurement(&self, measurement: &str)
Remove all entries for a measurement.
Sourcepub fn update_count(&self) -> usize
pub fn update_count(&self) -> usize
Returns the total number of updates applied.
Trait Implementations§
Source§impl Debug for LastValueCache
impl Debug for LastValueCache
Auto Trait Implementations§
impl !Freeze for LastValueCache
impl !RefUnwindSafe for LastValueCache
impl Send for LastValueCache
impl Sync for LastValueCache
impl Unpin for LastValueCache
impl UnsafeUnpin for LastValueCache
impl UnwindSafe for LastValueCache
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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