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

TAKETODAY / today-infrastructure / 18154768944

01 Oct 2025 07:26AM UTC coverage: 81.882% (-0.005%) from 81.887%
18154768944

push

github

web-flow
Merge pull request #290 from TAKETODAY/dev/jspecify

jspecify

59788 of 78013 branches covered (76.64%)

Branch coverage included in aggregate %.

141239 of 167496 relevant lines covered (84.32%)

3.6 hits per line

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

63.16
today-context/src/main/java/infra/cache/support/NoOpCache.java
1
/*
2
 * Copyright 2017 - 2025 the original author or authors.
3
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see [https://www.gnu.org/licenses/]
16
 */
17

18
package infra.cache.support;
19

20
import org.jspecify.annotations.Nullable;
21

22
import java.util.concurrent.CompletableFuture;
23
import java.util.function.Supplier;
24

25
import infra.cache.Cache;
26
import infra.lang.Assert;
27
import infra.util.function.ThrowingFunction;
28

29
/**
30
 * A no operation {@link Cache} implementation suitable for disabling caching.
31
 *
32
 * <p>Will simply accept any items into the cache not actually storing them.
33
 *
34
 * @author Costin Leau
35
 * @author Stephane Nicoll
36
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
37
 * @since 4.0 2022/1/26 14:15
38
 */
39
public class NoOpCache implements Cache {
40

41
  private final String name;
42

43
  /**
44
   * Create a {@link NoOpCache} instance with the specified name.
45
   *
46
   * @param name the name of the cache
47
   */
48
  public NoOpCache(String name) {
2✔
49
    Assert.notNull(name, "Cache name is required");
3✔
50
    this.name = name;
3✔
51
  }
1✔
52

53
  @Override
54
  public String getName() {
55
    return this.name;
3✔
56
  }
57

58
  @Override
59
  public Object getNativeCache() {
60
    return this;
2✔
61
  }
62

63
  @Override
64
  @Nullable
65
  public ValueWrapper get(Object key) {
66
    return null;
2✔
67
  }
68

69
  @Override
70
  @Nullable
71
  public <T> T get(Object key, @Nullable Class<T> type) {
72
    return null;
2✔
73
  }
74

75
  @Nullable
76
  @Override
77
  public <K, V> V get(K key, ThrowingFunction<? super K, ? extends V> valueLoader) {
78
    try {
79
      return valueLoader.applyWithException(key);
4✔
80
    }
81
    catch (Throwable ex) {
1✔
82
      throw new ValueRetrievalException(key, valueLoader, ex);
7✔
83
    }
84
  }
85

86
  @Override
87
  @Nullable
88
  public CompletableFuture<?> retrieve(Object key) {
89
    return null;
×
90
  }
91

92
  @Override
93
  public <T> CompletableFuture<T> retrieve(Object key, Supplier<CompletableFuture<T>> valueLoader) {
94
    return valueLoader.get();
×
95
  }
96

97
  @Override
98
  public void put(Object key, @Nullable Object value) {
99
  }
1✔
100

101
  @Override
102
  @Nullable
103
  public ValueWrapper putIfAbsent(Object key, @Nullable Object value) {
104
    return null;
×
105
  }
106

107
  @Override
108
  public void evict(Object key) {
109
  }
×
110

111
  @Override
112
  public boolean evictIfPresent(Object key) {
113
    return false;
×
114
  }
115

116
  @Override
117
  public void clear() {
118
  }
×
119

120
  @Override
121
  public boolean invalidate() {
122
    return false;
×
123
  }
124

125
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc