• 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
/jcache/src/main/java/com/github/benmanes/caffeine/jcache/event/JCacheEvictionListener.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.jcache.event;
17

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

20
import javax.cache.Cache;
21

22
import org.jspecify.annotations.Nullable;
23

24
import com.github.benmanes.caffeine.cache.RemovalCause;
25
import com.github.benmanes.caffeine.cache.RemovalListener;
26
import com.github.benmanes.caffeine.jcache.Expirable;
27
import com.github.benmanes.caffeine.jcache.management.JCacheStatisticsMXBean;
28

29
/**
30
 * A listener that provides an adapter to publish events in the order of the actions being performed
31
 * on a key.
32
 *
33
 * @author ben.manes@gmail.com (Ben Manes)
34
 */
35
public final class JCacheEvictionListener<K, V> implements RemovalListener<K, Expirable<V>> {
36
  private final JCacheStatisticsMXBean statistics;
37
  private final EventDispatcher<K, V> dispatcher;
38

39
  private @Nullable Cache<K, V> cache;
40

41
  public JCacheEvictionListener(EventDispatcher<K, V> dispatcher,
42
      JCacheStatisticsMXBean statistics) {
×
43
    this.dispatcher = requireNonNull(dispatcher);
×
44
    this.statistics = requireNonNull(statistics);
×
45
  }
×
46

47
  /**
48
   * Sets the cache instance that was created with this listener.
49
   *
50
   * @param cache the cache that uses this loader
51
   */
52
  public void setCache(Cache<K, V> cache) {
53
    this.cache = requireNonNull(cache);
×
54
  }
×
55

56
  @Override
57
  public void onRemoval(@Nullable K key, @Nullable Expirable<V> expirable, RemovalCause cause) {
58
    requireNonNull(key);
×
59
    requireNonNull(cache);
×
60
    requireNonNull(expirable);
×
61
    V value = expirable.get();
×
62
    if (cause == RemovalCause.EXPIRED) {
×
63
      dispatcher.publishExpiredQuietly(cache, key, value);
×
64
    } else {
65
      dispatcher.publishRemovedQuietly(cache, key, value);
×
66
    }
67
    statistics.recordEvictions(1L);
×
68
  }
×
69
}
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