• 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/SerializationProxy.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.UNSET_INT;
19

20
import java.io.Serializable;
21
import java.time.Duration;
22

23
import org.jspecify.annotations.Nullable;
24

25
/**
26
 * Serializes the configuration of the cache, reconstituting it as a {@link Cache},
27
 * {@link LoadingCache}, {@link AsyncCache}, or {@link AsyncLoadingCache} using {@link Caffeine}
28
 * upon deserialization. The data held by the cache is not retained.
29
 *
30
 * @author ben.manes@gmail.com (Ben Manes)
31
 */
32
@SuppressWarnings("serial")
33
final class SerializationProxy<K, V> implements Serializable {
×
34
  private static final long serialVersionUID = 1;
35

36
  boolean async;
37
  boolean weakKeys;
38
  boolean weakValues;
39
  boolean softValues;
40
  boolean isRecordingStats;
41
  long refreshAfterWriteNanos;
42
  long expiresAfterWriteNanos;
43
  long expiresAfterAccessNanos;
44
  long maximumSize = UNSET_INT;
×
45
  long maximumWeight = UNSET_INT;
×
46

47
  @Nullable Ticker ticker;
48
  @Nullable Expiry<?, ?> expiry;
49
  @Nullable Weigher<?, ?> weigher;
50
  @Nullable AsyncCacheLoader<?, ?> cacheLoader;
51
  @Nullable RemovalListener<?, ?> removalListener;
52
  @Nullable RemovalListener<?, ?> evictionListener;
53

54
  Caffeine<Object, Object> recreateCaffeine() {
55
    var builder = Caffeine.newBuilder();
×
56
    if (ticker != null) {
×
57
      builder.ticker(ticker);
×
58
    }
59
    if (isRecordingStats) {
×
60
      builder.recordStats();
×
61
    }
62
    if (maximumSize != UNSET_INT) {
×
63
      builder.maximumSize(maximumSize);
×
64
    }
65
    if (weigher != null) {
×
66
      @SuppressWarnings("unchecked")
67
      var castedWeigher = (Weigher<Object, Object>) weigher;
×
68
      builder.maximumWeight(maximumWeight);
×
69
      builder.weigher(castedWeigher);
×
70
    }
71
    if (expiry != null) {
×
72
      builder.expireAfter(expiry);
×
73
    }
74
    if (expiresAfterWriteNanos > 0) {
×
75
      builder.expireAfterWrite(Duration.ofNanos(expiresAfterWriteNanos));
×
76
    }
77
    if (expiresAfterAccessNanos > 0) {
×
78
      builder.expireAfterAccess(Duration.ofNanos(expiresAfterAccessNanos));
×
79
    }
80
    if (refreshAfterWriteNanos > 0) {
×
81
      builder.refreshAfterWrite(Duration.ofNanos(refreshAfterWriteNanos));
×
82
    }
83
    if (weakKeys) {
×
84
      builder.weakKeys();
×
85
    }
86
    if (weakValues) {
×
87
      builder.weakValues();
×
88
    }
89
    if (softValues) {
×
90
      builder.softValues();
×
91
    }
92
    if (removalListener != null) {
×
93
      builder.removalListener(removalListener);
×
94
    }
95
    if (evictionListener != null) {
×
96
      builder.evictionListener(evictionListener);
×
97
    }
98
    return builder;
×
99
  }
100

101
  Object readResolve() {
102
    var builder = recreateCaffeine();
×
103
    if (async) {
×
104
      if (cacheLoader == null) {
×
105
        return builder.buildAsync();
×
106
      }
107
      @SuppressWarnings("unchecked")
108
      var loader = (AsyncCacheLoader<K, V>) cacheLoader;
×
109
      return builder.buildAsync(loader);
×
110
    }
111

112
    if (cacheLoader == null) {
×
113
      return builder.build();
×
114
    }
115
    @SuppressWarnings("unchecked")
116
    var loader = (CacheLoader<K, V>) cacheLoader;
×
117
    return builder.build(loader);
×
118
  }
119
}
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