27 config.enable_metrics,
40 cache_.put(key, std::move(result));
44 return cache_.invalidate(key);
48 return cache_.invalidate_if(
50 return key.size() >= prefix.size() &&
51 key.compare(0, prefix.size(), prefix) == 0;
58 return cache_.invalidate_if(
65 auto slash_pos = key.find(
'/');
66 if (slash_pos != std::string::npos) {
67 auto level_start = slash_pos + 1;
68 auto colon_pos = key.find(
':', level_start);
69 if (colon_pos != std::string::npos) {
70 auto key_level = key.substr(level_start, colon_pos - level_start);
83 return cache_.purge_expired();
112 const std::vector<std::pair<std::string, std::string>>& params) {
115 auto sorted_params = params;
116 std::sort(sorted_params.begin(), sorted_params.end(),
117 [](
const auto& a,
const auto& b) { return a.first < b.first; });
119 std::ostringstream oss;
123 for (
const auto& [
name, value] : sorted_params) {
128 oss <<
name <<
"=" << value;
135 const std::string& calling_ae,
137 const std::vector<std::pair<std::string, std::string>>& params) {
148std::once_flag g_cache_init_flag;
149std::unique_ptr<query_cache> g_query_cache;
151bool g_config_pending =
false;
153void init_global_cache() {
154 if (g_config_pending) {
155 g_query_cache = std::make_unique<query_cache>(g_pending_config);
157 g_query_cache = std::make_unique<query_cache>();
164 std::call_once(g_cache_init_flag, init_global_cache);
165 return *g_query_cache;
175 g_pending_config = config;
176 g_config_pending =
true;
DICOM query result cache with monitoring integration.
std::optional< cached_query_result > get(const key_type &key)
Retrieve a cached query result.
static std::string build_key(const std::string &query_level, const std::vector< std::pair< std::string, std::string > > ¶ms)
Build a cache key from query parameters.
void reset_stats() noexcept
Reset cache statistics.
string_lru_cache< cached_query_result > cache_
bool empty() const
Check if the cache is empty.
size_type size() const
Get the current number of cached entries.
void clear()
Remove all entries from the cache.
double hit_rate() const noexcept
Get the cache hit rate.
size_type max_size() const noexcept
Get the maximum cache size.
const cache_stats & stats() const noexcept
Get cache statistics.
bool invalidate(const key_type &key)
Remove a specific entry from the cache.
size_type purge_expired()
Remove all expired entries.
void put(const key_type &key, const cached_query_result &result)
Store a query result in the cache.
static std::string build_key_with_ae(const std::string &calling_ae, const std::string &query_level, const std::vector< std::pair< std::string, std::string > > ¶ms)
Build a cache key with AE title prefix.
size_type invalidate_by_prefix(const std::string &prefix)
query_cache(const query_cache_config &config=query_cache_config{})
Construct a query cache with the given configuration.
size_type invalidate_by_query_level(const std::string &query_level)
Remove all entries for a specific query level.
query_cache & global_query_cache()
Get the global query cache instance.
bool configure_global_cache(const query_cache_config &config)
Configure the global query cache.
query_level
DICOM Query/Retrieve level enumeration.
DICOM query result cache with monitoring integration.
Configuration options for the LRU cache.
Statistics for cache performance monitoring.
double hit_rate() const noexcept
Calculate the cache hit rate.
Wrapper for cached query results.
Configuration for the query cache.