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

ben-manes / caffeine / #5573

03 Jul 2026 08:24PM UTC coverage: 98.975% (-1.0%) from 99.988%
#5573

push

github

ben-manes
Bound per-cycle expiration to amortize idle-recovery spikes

Cap expireAfterAccessEntries/expireAfterWriteEntries at
EXPIRATION_THRESHOLD evictions per maintenance cycle, then re-arm
via PROCESSING_TO_REQUIRED so the backlog drains across cycles.
Mirrors drainWriteBuffer's cap; keeps a large expired population
from stalling a writer-assist under evictionLock. The validation
subject pumps cleanUp until IDLE to drain the re-armed backlog.

3996 of 4072 branches covered (98.13%)

16 of 16 new or added lines in 1 file covered. (100.0%)

84 existing lines in 13 files now uncovered.

8205 of 8290 relevant lines covered (98.97%)

0.99 hits per line

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

31.43
/caffeine/src/main/java/com/github/benmanes/caffeine/cache/stats/GuardedStatsCounter.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.stats;
17

18
import static java.util.Objects.requireNonNull;
19

20
import java.lang.System.Logger;
21
import java.lang.System.Logger.Level;
22

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

25
/**
26
 * A {@link StatsCounter} implementation that suppresses and logs any exception thrown by the
27
 * delegate <code>statsCounter</code>.
28
 *
29
 * @author ben.manes@gmail.com (Ben Manes)
30
 */
31
final class GuardedStatsCounter implements StatsCounter {
32
  static final Logger logger = System.getLogger(GuardedStatsCounter.class.getName());
1✔
33

34
  final StatsCounter delegate;
35

36
  GuardedStatsCounter(StatsCounter delegate) {
1✔
37
    this.delegate = requireNonNull(delegate);
1✔
38
  }
1✔
39

40
  @Override
41
  public void recordHits(int count) {
42
    try {
43
      delegate.recordHits(count);
1✔
UNCOV
44
    } catch (Throwable t) {
×
UNCOV
45
      logger.log(Level.WARNING, "Exception thrown by stats counter", t);
×
46
    }
1✔
47
  }
1✔
48

49
  @Override
50
  public void recordMisses(int count) {
51
    try {
UNCOV
52
      delegate.recordMisses(count);
×
UNCOV
53
    } catch (Throwable t) {
×
UNCOV
54
      logger.log(Level.WARNING, "Exception thrown by stats counter", t);
×
UNCOV
55
    }
×
UNCOV
56
  }
×
57

58
  @Override
59
  public void recordLoadSuccess(long loadTime) {
60
    try {
UNCOV
61
      delegate.recordLoadSuccess(loadTime);
×
UNCOV
62
    } catch (Throwable t) {
×
UNCOV
63
      logger.log(Level.WARNING, "Exception thrown by stats counter", t);
×
UNCOV
64
    }
×
UNCOV
65
  }
×
66

67
  @Override
68
  public void recordLoadFailure(long loadTime) {
69
    try {
UNCOV
70
      delegate.recordLoadFailure(loadTime);
×
UNCOV
71
    } catch (Throwable t) {
×
UNCOV
72
      logger.log(Level.WARNING, "Exception thrown by stats counter", t);
×
UNCOV
73
    }
×
UNCOV
74
  }
×
75

76
  @Override
77
  public void recordEviction(int weight, RemovalCause cause) {
78
    requireNonNull(cause);
1✔
79
    try {
80
      delegate.recordEviction(weight, cause);
1✔
UNCOV
81
    } catch (Throwable t) {
×
UNCOV
82
      logger.log(Level.WARNING, "Exception thrown by stats counter", t);
×
83
    }
1✔
84
  }
1✔
85

86
  @Override
87
  public CacheStats snapshot() {
88
    try {
UNCOV
89
      return delegate.snapshot();
×
UNCOV
90
    } catch (Throwable t) {
×
UNCOV
91
      logger.log(Level.WARNING, "Exception thrown by stats counter", t);
×
UNCOV
92
      return CacheStats.empty();
×
93
    }
94
  }
95

96
  @Override
97
  public String toString() {
UNCOV
98
    return delegate.toString();
×
99
  }
100
}
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