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

ben-manes / caffeine / #5257

25 Jan 2026 09:44AM UTC coverage: 99.975% (-0.03%) from 100.0%
#5257

push

github

ben-manes
modernize the jcache tests and replace the base class with a test fixture

3834 of 3838 branches covered (99.9%)

7868 of 7870 relevant lines covered (99.97%)

1.0 hits per line

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

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

18
import static java.util.Locale.US;
19
import static java.util.Objects.requireNonNull;
20

21
/**
22
 * A value with an expiration timestamp.
23
 *
24
 * @author ben.manes@gmail.com (Ben Manes)
25
 */
26
public final class Expirable<V> {
27
  private final V value;
28

29
  private volatile long expireTimeMillis;
30

31
  public Expirable(V value, long expireTimeMillis) {
1✔
32
    this.value = requireNonNull(value);
1✔
33
    this.expireTimeMillis = expireTimeMillis;
1✔
34
  }
1✔
35

36
  /** Returns the value. */
37
  public V get() {
38
    return value;
1✔
39
  }
40

41
  /** Returns the time, in milliseconds, when the value will expire. */
42
  public long getExpireTimeMillis() {
43
    return expireTimeMillis;
1✔
44
  }
45

46
  /** Specifies the time, in milliseconds, when the value will expire. */
47
  public void setExpireTimeMillis(long expireTimeMillis) {
48
    this.expireTimeMillis = expireTimeMillis;
1✔
49
  }
1✔
50

51
  /** Returns if the value has expired and is eligible for eviction. */
52
  public boolean hasExpired(long currentTimeMillis) {
53
    return (currentTimeMillis - expireTimeMillis) >= 0;
1✔
54
  }
55

56
  /** Returns if the value will never expire. */
57
  public boolean isEternal() {
58
    return (expireTimeMillis == Long.MAX_VALUE);
1✔
59
  }
60

61
  @Override
62
  public String toString() {
63
    return String.format(US, "%s{value=%s, expireTimeMillis=%,d}",
×
64
        getClass().getSimpleName(), value, expireTimeMillis);
×
65
  }
66
}
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