Skip to main content

LastValueCache

Struct LastValueCache 

Source
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

Source

pub fn new() -> Self

Create a new, empty LVC with no entry limit.

Source

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

Source

pub fn with_capacity(n: usize) -> Self

Create an LVC with pre-allocated capacity for n series.

Source

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

Source

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.

Source

pub fn get_by_key(&self, key: &SeriesKey) -> Option<Point>

Look up by SeriesKey.

Source

pub fn evict(&self, measurement: &str, tags: &BTreeMap<String, String>)

Remove a series from the cache.

Source

pub fn evict_by_key(&self, key: &SeriesKey)

Remove a series by its SeriesKey.

Source

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.

Source

pub fn evict_measurement(&self, measurement: &str)

Remove all entries for a measurement.

Source

pub fn clear(&self)

Clear all entries.

Source

pub fn len(&self) -> usize

Returns the number of cached series.

Source

pub fn is_empty(&self) -> bool

Returns true if the cache is empty.

Source

pub fn update_count(&self) -> usize

Returns the total number of updates applied.

Trait Implementations§

Source§

impl Debug for LastValueCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LastValueCache

Source§

fn default() -> Self

Returns the “default value” for a type. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more