Skip to content

SignalValueCache

class SignalValueCache

@brief LRU Cache for signal values with statistics

Caches recently accessed signal values to improve query performance without loading the entire file into memory.

Features: - Per-signal LRU cache - Hit/miss statistics - Adaptive sizing - Cache warming

Memory: O(cache_size) bounded

Functions

Name Description
SignalValueCache @brief Construct cache with given entry capacity per signal capacity_per_signal : Max entries to cache per signal (default: 1000)
add @brief Add value to cache signal_name : Signal identifier index : Time index value : Signal value at this index
get @brief Try to retrieve cached value signal_name : Signal identifier index : Time index Return : Cached value if present, std::nullopt otherwise
clear @brief Clear all cached values
estimated_memory_bytes @brief Get estimated memory usage Return : Estimated bytes used by cache
get_hit_rate @brief Get cache hit rate signal_name : Signal identifier Return : Hit rate percentage (0-100)
get_statistics @brief Get overall cache statistics Return : String with hit rate, evictions, etc
warm_cache @brief Warm cache with frequently accessed signals signal_names : Vector of signal names to pre-load
adapt_cache_size @brief Adapt cache size based on performance Increases capacity if hit rate is low, decreases if memory-constrained

Function Details

SignalValueCache

explicit SignalValueCache(size_t capacity_per_signal = 1000)

@brief Construct cache with given entry capacity per signal

capacity_per_signal
Max entries to cache per signal (default: 1000)

adapt_cache_size

void adapt_cache_size()

@brief Adapt cache size based on performance

Increases capacity if hit rate is low, decreases if memory-constrained

add

void add(const std::string& signal_name, int index, const Value& value)

@brief Add value to cache

signal_name
Signal identifier
index
Time index
value
Signal value at this index

clear

void clear()

@brief Clear all cached values

estimated_memory_bytes

size_t estimated_memory_bytes() const

@brief Get estimated memory usage

Return
Estimated bytes used by cache

get

std::optional<Value> get(const std::string& signal_name, int index)

@brief Try to retrieve cached value

signal_name
Signal identifier
index
Time index
Return
Cached value if present, std::nullopt otherwise

get_hit_rate

double get_hit_rate(const std::string& signal_name) const

@brief Get cache hit rate

signal_name
Signal identifier
Return
Hit rate percentage (0-100)

get_statistics

std::string get_statistics() const

@brief Get overall cache statistics

Return
String with hit rate, evictions, etc

warm_cache

void warm_cache(const std::vector<std::string>& signal_names)

@brief Warm cache with frequently accessed signals

signal_names
Vector of signal names to pre-load