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 {
@@ -41,9 +42,12 @@ class LRUCachePolicy : public CachePolicy {
4142 : CachePolicy(type, capacity, stale_sweep_time_s, enable_prune),
4243 _lru_cache_type (lru_cache_type) {
4344 if (check_capacity (capacity, num_shards)) {
44- _cache = std::shared_ptr<ShardedLRUCache>(
45+ auto cache = std::shared_ptr<ShardedLRUCache>(
4546 new ShardedLRUCache (type_string (type), capacity, lru_cache_type, num_shards,
4647 element_count_capacity, is_lru_k));
48+ cache->set_metrics_recorder (
49+ create_be_lru_cache_metrics_recorder (type_string (type), cache.get ()));
50+ _cache = std::move (cache);
4751 } else {
4852 _cache = std::make_shared<doris::DummyLRUCache>();
4953 }
@@ -59,10 +63,13 @@ class LRUCachePolicy : public CachePolicy {
5963 : CachePolicy(type, capacity, stale_sweep_time_s, enable_prune),
6064 _lru_cache_type(lru_cache_type) {
6165 if (check_capacity (capacity, num_shards)) {
62- _cache = std::shared_ptr<ShardedLRUCache>(
66+ auto cache = std::shared_ptr<ShardedLRUCache>(
6367 new ShardedLRUCache (type_string (type), capacity, lru_cache_type, num_shards,
6468 cache_value_time_extractor, cache_value_check_timestamp,
6569 element_count_capacity, is_lru_k));
70+ cache->set_metrics_recorder (
71+ create_be_lru_cache_metrics_recorder (type_string (type), cache.get ()));
72+ _cache = std::move (cache);
6673 } else {
6774 _cache = std::make_shared<doris::DummyLRUCache>();
6875 }
@@ -127,7 +134,7 @@ class LRUCachePolicy : public CachePolicy {
127134 ->set_tracking_bytes (tracking_bytes, _mem_tracker, value_tracking_bytes,
128135 _value_mem_tracker);
129136 }
130- return _cache->insert (key, value, charge, priority);
137+ return _cache->insert (key, value, charge, priority, cache_value_deleter<LRUCacheValueBase> );
131138 }
132139
133140 void for_each_entry (const std::function<void (const LRUHandle*)>& visitor) {
0 commit comments