• 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

90.32
today-context/src/main/java/infra/cache/interceptor/AbstractCacheResolver.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.interceptor;
19

20
import org.jspecify.annotations.Nullable;
21

22
import java.util.ArrayList;
23
import java.util.Collection;
24
import java.util.Collections;
25

26
import infra.beans.factory.InitializingBean;
27
import infra.cache.Cache;
28
import infra.cache.CacheManager;
29
import infra.lang.Assert;
30

31
/**
32
 * A base {@link CacheResolver} implementation that requires the concrete
33
 * implementation to provide the collection of cache name(s) based on the
34
 * invocation context.
35
 *
36
 * @author Stephane Nicoll
37
 * @author Juergen Hoeller
38
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
39
 * @since 4.0
40
 */
41
public abstract class AbstractCacheResolver implements CacheResolver, InitializingBean {
42

43
  @Nullable
44
  private CacheManager cacheManager;
45

46
  /**
47
   * Construct a new {@code AbstractCacheResolver}.
48
   *
49
   * @see #setCacheManager
50
   */
51
  protected AbstractCacheResolver() {
2✔
52
  }
1✔
53

54
  /**
55
   * Construct a new {@code AbstractCacheResolver} for the given {@link CacheManager}.
56
   *
57
   * @param cacheManager the CacheManager to use
58
   */
59
  protected AbstractCacheResolver(CacheManager cacheManager) {
2✔
60
    this.cacheManager = cacheManager;
3✔
61
  }
1✔
62

63
  /**
64
   * Set the {@link CacheManager} that this instance should use.
65
   */
66
  public void setCacheManager(CacheManager cacheManager) {
67
    this.cacheManager = cacheManager;
3✔
68
  }
1✔
69

70
  /**
71
   * Return the {@link CacheManager} that this instance uses.
72
   */
73
  public CacheManager getCacheManager() {
74
    Assert.state(this.cacheManager != null, "No CacheManager set");
7!
75
    return this.cacheManager;
3✔
76
  }
77

78
  @Override
79
  public void afterPropertiesSet() {
80
    Assert.notNull(this.cacheManager, "CacheManager is required");
4✔
81
  }
1✔
82

83
  @Override
84
  public Collection<? extends Cache> resolveCaches(CacheOperationInvocationContext<?> context) {
85
    Collection<String> cacheNames = getCacheNames(context);
4✔
86
    if (cacheNames == null) {
2✔
87
      return Collections.emptyList();
2✔
88
    }
89
    ArrayList<Cache> result = new ArrayList<>(cacheNames.size());
6✔
90
    CacheManager cacheManager = getCacheManager();
3✔
91
    for (String cacheName : cacheNames) {
10✔
92
      Cache cache = cacheManager.getCache(cacheName);
4✔
93
      if (cache == null) {
2!
94
        throw new IllegalArgumentException("Cannot find cache named '%s' for %s".formatted(cacheName, context.getOperation()));
×
95
      }
96
      result.add(cache);
4✔
97
    }
1✔
98
    return result;
2✔
99
  }
100

101
  /**
102
   * Provide the name of the cache(s) to resolve against the current cache manager.
103
   * <p>It is acceptable to return {@code null} to indicate that no cache could
104
   * be resolved for this invocation.
105
   *
106
   * @param context the context of the particular invocation
107
   * @return the cache name(s) to resolve, or {@code null} if no cache should be resolved
108
   */
109
  @Nullable
110
  protected abstract Collection<String> getCacheNames(CacheOperationInvocationContext<?> context);
111

112
}
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