Coverage Report

Created: 2026-03-15 08:11

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
26
        : LRUCachePolicy(CachePolicy::CacheType::COMMON_OBJ_LRU_CACHE, capacity,
24
26
                         LRUCacheType::NUMBER, config::common_obj_lru_cache_stale_sweep_time_sec,
25
26
                         /*num shards*/ 32, /*element count capacity */ 0,
26
26
                         /*enable prune*/ true, /*is lru-k*/ true),
27
26
          _enabled(capacity > 0) {}
28
29
67
bool ObjLRUCache::lookup(const ObjKey& key, CacheHandle* handle) {
30
67
    if (!_enabled) {
31
0
        return false;
32
0
    }
33
67
    auto* lru_handle = LRUCachePolicy::lookup(key.key);
34
67
    if (!lru_handle) {
35
        // cache miss
36
37
        return false;
37
37
    }
38
30
    *handle = CacheHandle(this, lru_handle);
39
30
    return true;
40
67
}
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
0
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
0
    return true;
53
0
}
54
55
} // namespace doris