Coverage Report

Created: 2026-03-15 18:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/util/obj_lru_cache.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "util/obj_lru_cache.h"
19
20
namespace doris {
21
22
ObjLRUCache::ObjLRUCache(int64_t capacity, uint32_t num_shards)
23
33
        : LRUCachePolicy(CachePolicy::CacheType::COMMON_OBJ_LRU_CACHE, capacity,
24
33
                         LRUCacheType::NUMBER, config::common_obj_lru_cache_stale_sweep_time_sec,
25
33
                         /*num shards*/ 32, /*element count capacity */ 0,
26
33
                         /*enable prune*/ true, /*is lru-k*/ true),
27
33
          _enabled(capacity > 0) {}
28
29
287
bool ObjLRUCache::lookup(const ObjKey& key, CacheHandle* handle) {
30
287
    if (!_enabled) {
31
0
        return false;
32
0
    }
33
287
    auto* lru_handle = LRUCachePolicy::lookup(key.key);
34
287
    if (!lru_handle) {
35
        // cache miss
36
224
        return false;
37
224
    }
38
63
    *handle = CacheHandle(this, lru_handle);
39
63
    return true;
40
287
}
41
42
0
void ObjLRUCache::erase(const ObjKey& key) {
43
0
    if (_enabled) {
44
0
        LRUCachePolicy::erase(key.key);
45
0
    }
46
0
}
47
48
87
bool ObjLRUCache::exceed_prune_limit() {
49
    // just return true to prune all cached obj.
50
    // Because ObjLRUCache is counted with number, not memory.
51
    // Simple prune all
52
87
    return true;
53
87
}
54
55
} // namespace doris