2222#include < memory>
2323
2424#include " common/be_mock_util.h"
25+ #include " cpp/lru_cache.h"
2526#include " runtime/memory/cache_policy.h"
2627#include " runtime/memory/lru_cache_value_base.h"
2728#include " runtime/memory/mem_tracker_limiter.h"
2829#include " runtime/thread_context.h"
29- #include " util/lru_cache .h"
30+ #include " util/be_lru_cache_metrics .h"
3031#include " util/time.h"
3132
3233namespace doris {
@@ -40,9 +41,12 @@ class LRUCachePolicy : public CachePolicy {
4041 : CachePolicy(type, capacity, stale_sweep_time_s, enable_prune),
4142 _lru_cache_type (lru_cache_type) {
4243 if (check_capacity (capacity, num_shards)) {
43- _cache = std::shared_ptr<ShardedLRUCache>(
44+ auto cache = std::shared_ptr<ShardedLRUCache>(
4445 new ShardedLRUCache (type_string (type), capacity, lru_cache_type, num_shards,
4546 element_count_capacity, is_lru_k));
47+ cache->set_metrics_recorder (
48+ create_be_lru_cache_metrics_recorder (type_string (type), cache.get ()));
49+ _cache = std::move (cache);
4650 } else {
4751 _cache = std::make_shared<doris::DummyLRUCache>();
4852 }
@@ -58,10 +62,13 @@ class LRUCachePolicy : public CachePolicy {
5862 : CachePolicy(type, capacity, stale_sweep_time_s, enable_prune),
5963 _lru_cache_type(lru_cache_type) {
6064 if (check_capacity (capacity, num_shards)) {
61- _cache = std::shared_ptr<ShardedLRUCache>(
65+ auto cache = std::shared_ptr<ShardedLRUCache>(
6266 new ShardedLRUCache (type_string (type), capacity, lru_cache_type, num_shards,
6367 cache_value_time_extractor, cache_value_check_timestamp,
6468 element_count_capacity, is_lru_k));
69+ cache->set_metrics_recorder (
70+ create_be_lru_cache_metrics_recorder (type_string (type), cache.get ()));
71+ _cache = std::move (cache);
6572 } else {
6673 _cache = std::make_shared<doris::DummyLRUCache>();
6774 }
@@ -126,7 +133,7 @@ class LRUCachePolicy : public CachePolicy {
126133 ->set_tracking_bytes (tracking_bytes, _mem_tracker, value_tracking_bytes,
127134 _value_mem_tracker);
128135 }
129- return _cache->insert (key, value, charge, priority);
136+ return _cache->insert (key, value, charge, priority, cache_value_deleter<LRUCacheValueBase> );
130137 }
131138
132139 void for_each_entry (const std::function<void (const LRUHandle*)>& visitor) {
0 commit comments