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

ben-manes / caffeine / #5173

29 Dec 2025 05:27AM UTC coverage: 0.0% (-100.0%) from 100.0%
#5173

push

github

ben-manes
speed up development ci build

0 of 3838 branches covered (0.0%)

0 of 7869 relevant lines covered (0.0%)

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/stats/StatsCounter.java
1
/*
2
 * Copyright 2014 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.stats;
17

18
import java.util.Map;
19

20
import org.jspecify.annotations.NullMarked;
21

22
import com.github.benmanes.caffeine.cache.Cache;
23
import com.github.benmanes.caffeine.cache.RemovalCause;
24

25
/**
26
 * Accumulates statistics during the operation of a {@link Cache} for presentation by
27
 * {@link Cache#stats}.
28
 *
29
 * @author ben.manes@gmail.com (Ben Manes)
30
 */
31
@NullMarked
32
public interface StatsCounter {
33

34
  /**
35
   * Records cache hits. This should be called when a cache request returns a cached value.
36
   *
37
   * @param count the number of hits to record
38
   */
39
  void recordHits(int count);
40

41
  /**
42
   * Records cache misses. This should be called when a cache request returns a value that was not
43
   * found in the cache. This method should be called by the loading thread and by threads blocking
44
   * on the load. Multiple concurrent calls to {@link Cache} lookup methods with the same key on an
45
   * absent value should result in a single call to either {@code recordLoadSuccess} or
46
   * {@code recordLoadFailure} and multiple calls to this method, despite all being served by the
47
   * results of a single load operation.
48
   *
49
   * @param count the number of misses to record
50
   */
51
  void recordMisses(int count);
52

53
  /**
54
   * Records the successful load of a new entry. This method should be called when a cache request
55
   * causes an entry to be loaded (such as by {@link Cache#get} or {@link Map#computeIfAbsent}) and
56
   * the loading completes successfully. In contrast to {@link #recordMisses}, this method should
57
   * only be called by the loading thread.
58
   *
59
   * @param loadTime the number of nanoseconds the cache spent computing or retrieving the new value
60
   */
61
  void recordLoadSuccess(long loadTime);
62

63
  /**
64
   * Records the failed load of a new entry. This method should be called when a cache request
65
   * causes an entry to be loaded (such as by {@link Cache#get} or {@link Map#computeIfAbsent}), but
66
   * an exception is thrown while loading the entry or the loading function returns null. In
67
   * contrast to {@link #recordMisses}, this method should only be called by the loading thread.
68
   *
69
   * @param loadTime the number of nanoseconds the cache spent computing or retrieving the new value
70
   *        prior to discovering the value doesn't exist or an exception being thrown
71
   */
72
  void recordLoadFailure(long loadTime);
73

74
  /**
75
   * Records the eviction of an entry from the cache. This should only been called when an entry is
76
   * evicted due to the cache's eviction strategy, and not as a result of manual
77
   * {@link Cache#invalidate invalidations}.
78
   *
79
   * @param weight the weight of the evicted entry
80
   * @param cause the reason for which the entry was removed
81
   */
82
  void recordEviction(int weight, RemovalCause cause);
83

84
  /**
85
   * Returns a snapshot of this counter's values. Note that this may be an inconsistent view, as it
86
   * may be interleaved with update operations.
87
   * <p>
88
   * <b>Note:</b> the values of the metrics are undefined in case of overflow (though it is
89
   * guaranteed not to throw an exception). If you require specific handling, we recommend
90
   * implementing your own stats collector.
91
   *
92
   * @return a snapshot of this counter's values
93
   */
94
  CacheStats snapshot();
95

96
  /**
97
   * Returns an accumulator that does not record any cache events.
98
   *
99
   * @return an accumulator that does not record metrics
100
   */
101
  static StatsCounter disabledStatsCounter() {
102
    return DisabledStatsCounter.INSTANCE;
×
103
  }
104

105
  /**
106
   * Returns an accumulator that suppresses and logs any exception thrown by the delegate
107
   * {@code statsCounter}.
108
   *
109
   * @param statsCounter the accumulator to delegate to
110
   * @return an accumulator that suppresses and logs any exception thrown by the delegate
111
   */
112
  static StatsCounter guardedStatsCounter(StatsCounter statsCounter) {
113
    return (statsCounter instanceof GuardedStatsCounter)
×
114
        ? statsCounter
×
115
        : new GuardedStatsCounter(statsCounter);
×
116
  }
117
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc