• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ben-manes / caffeine / #5707

02 Aug 2026 12:45AM UTC coverage: 0.106% (-99.9%) from 100.0%
#5707

push

github

ben-manes
fix wikibench trace reader after overly strict audit fixes

0 of 4235 branches covered (0.0%)

9 of 8528 relevant lines covered (0.11%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalManualCache.java
1
/*
2
 * Copyright 2015 Ben Manes. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.github.benmanes.caffeine.cache;
17

18
import static com.github.benmanes.caffeine.cache.Caffeine.calculateHashMapCapacity;
19
import static java.util.Objects.requireNonNull;
20

21
import java.util.Collections;
22
import java.util.LinkedHashMap;
23
import java.util.LinkedHashSet;
24
import java.util.Map;
25
import java.util.Set;
26
import java.util.concurrent.ConcurrentMap;
27
import java.util.function.Function;
28

29
import org.jspecify.annotations.Nullable;
30

31
import com.github.benmanes.caffeine.cache.stats.CacheStats;
32
import com.google.errorprone.annotations.Var;
33

34
/**
35
 * This class provides a skeletal implementation of the {@link Cache} interface to minimize the
36
 * effort required to implement a {@link LocalCache}.
37
 *
38
 * @author ben.manes@gmail.com (Ben Manes)
39
 */
40
interface LocalManualCache<K, V> extends Cache<K, V> {
41

42
  /** Returns the backing {@link LocalCache} data store. */
43
  LocalCache<K, V> cache();
44

45
  @Override
46
  default long estimatedSize() {
47
    return cache().estimatedSize();
×
48
  }
49

50
  @Override
51
  default void cleanUp() {
52
    cache().cleanUp();
×
53
  }
×
54

55
  @Override
56
  default @Nullable V getIfPresent(K key) {
57
    return cache().getIfPresent(key, /* recordStats= */ true);
×
58
  }
59

60
  @Override
61
  @SuppressWarnings("NullAway")
62
  default @Nullable V get(K key, Function<? super K, ? extends V> mappingFunction) {
63
    return cache().computeIfAbsent(key, mappingFunction);
×
64
  }
65

66
  @Override
67
  default Map<K, V> getAllPresent(Iterable<? extends K> keys) {
68
    return cache().getAllPresent(keys);
×
69
  }
70

71
  @Override
72
  default Map<K, V> getAll(Iterable<? extends K> keys,
73
      Function<? super Set<? extends K>, ? extends Map<? extends K, ? extends V>> mappingFunction) {
74
    requireNonNull(mappingFunction);
×
75

76
    int initialCapacity = calculateHashMapCapacity(keys);
×
77
    var result = new LinkedHashMap<K, @Nullable V>(initialCapacity);
×
78
    for (K key : keys) {
×
79
      result.put(key, null);
×
80
    }
×
81
    var keysToLoad = new LinkedHashSet<K>(initialCapacity);
×
82
    var found = cache().getAllPresent(result.keySet());
×
83
    for (var entry : result.entrySet()) {
×
84
      V value = found.get(entry.getKey());
×
85
      if (value == null) {
×
86
        keysToLoad.add(entry.getKey());
×
87
      }
88
      entry.setValue(value);
×
89
    }
×
90
    if (keysToLoad.isEmpty()) {
×
91
      return found;
×
92
    }
93
    bulkLoad(keysToLoad, result, mappingFunction);
×
94

95
    @SuppressWarnings("NullableProblems")
96
    Map<K, V> unmodifiable = Collections.unmodifiableMap(result);
×
97
    return unmodifiable;
×
98
  }
99

100
  /**
101
   * Performs a non-blocking bulk load of the missing keys. Any missing entry that materializes
102
   * during the load are replaced when the loaded entries are inserted into the cache.
103
   */
104
  default void bulkLoad(Set<K> keysToLoad, Map<K, @Nullable V> result,
105
      Function<? super Set<? extends K>, ? extends Map<? extends K, ? extends V>> mappingFunction) {
106
    long startTime = cache().statsTicker().read();
×
107
    @Var boolean success = false;
×
108
    try {
109
      var loaded = mappingFunction.apply(Collections.unmodifiableSet(keysToLoad));
×
110
      loaded.forEach(cache()::put);
×
111
      for (K key : keysToLoad) {
×
112
        V value = loaded.get(key);
×
113
        if (value == null) {
×
114
          result.remove(key);
×
115
        } else {
116
          result.put(key, value);
×
117
        }
118
      }
×
119
      success = !loaded.isEmpty();
×
120
    } finally {
121
      long loadTime = cache().statsTicker().read() - startTime;
×
122
      if (success) {
×
123
        cache().statsCounter().recordLoadSuccess(loadTime);
×
124
      } else {
125
        cache().statsCounter().recordLoadFailure(loadTime);
×
126
      }
127
    }
128
  }
×
129

130
  @Override
131
  default void put(K key, V value) {
132
    cache().put(key, value);
×
133
  }
×
134

135
  @Override
136
  default void putAll(Map<? extends K, ? extends V> map) {
137
    cache().putAll(map);
×
138
  }
×
139

140
  @Override
141
  default void invalidate(K key) {
142
    cache().remove(key);
×
143
  }
×
144

145
  @Override
146
  default void invalidateAll(Iterable<? extends K> keys) {
147
    cache().invalidateAll(keys);
×
148
  }
×
149

150
  @Override
151
  default void invalidateAll() {
152
    cache().clear();
×
153
  }
×
154

155
  @Override
156
  default CacheStats stats() {
157
    return cache().statsCounter().snapshot();
×
158
  }
159

160
  @Override
161
  default ConcurrentMap<K, V> asMap() {
162
    return cache();
×
163
  }
164
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc