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

Hyshmily / hotkey / 28229667796

26 Jun 2026 09:31AM UTC coverage: 91.921% (+0.7%) from 91.258%
28229667796

push

github

Hyshmily
fix:Code quality improvement

Signed-off-by: Hyshmily <cxm8607@outlook.com>

1246 of 1421 branches covered (87.68%)

Branch coverage included in aggregate %.

33 of 33 new or added lines in 4 files covered. (100.0%)

1 existing line in 1 file now uncovered.

3510 of 3753 relevant lines covered (93.53%)

4.26 hits per line

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

91.67
/common/src/main/java/io/github/hyshmily/hotkey/cache/annotationsupporter/HotKeyCacheManager.java
1
/*
2
 * Copyright 2026 Hyshmily. 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 io.github.hyshmily.hotkey.cache.annotationsupporter;
17

18
import io.github.hyshmily.hotkey.HotKey;
19
import io.github.hyshmily.hotkey.autoconfigure.HotKeyProperties;
20
import org.jspecify.annotations.NonNull;
21
import org.springframework.cache.Cache;
22
import org.springframework.cache.CacheManager;
23

24
import java.util.Collection;
25
import java.util.Collections;
26
import java.util.concurrent.ConcurrentHashMap;
27
import java.util.concurrent.ConcurrentMap;
28

29
/**
30
 * Spring {@link CacheManager} implementation that lazily creates
31
 * {@link HotKeySpringCache} instances for each cache name requested by
32
 * {@code @Cacheable} / {@code @CachePut} / {@code @CacheEvict} annotations.
33
 *
34
 * <p>Caches are created on first access via {@link #getCache(String)} using
35
 * double-checked locking (ConcurrentHashMap read, then {@code synchronized}
36
 * create method, then re-check). This avoids redundant creation under
37
 * concurrent access while keeping the common read-fast path lock-free.
38
 *
39
 * <p>The {@link #getMissingCache(String)} method is {@code protected} so that
40
 * subclasses may override it to customise cache creation, following the
41
 * standard Spring extensibility pattern.
42
 *
43
 * @see HotKeySpringCache
44
 * @see org.springframework.cache.CacheManager
45
 */
46
public class HotKeyCacheManager implements CacheManager {
47

48
  private final ConcurrentMap<String, Cache> cacheMap = new ConcurrentHashMap<>();
5✔
49
  private final HotKey hotKey;
50
  private final HotKeyProperties properties;
51

52
  /**
53
   * Create a new {@code HotKeyCacheManager}.
54
   *
55
   * @param hotKey     the HotKey facade
56
   * @param properties the HotKey configuration properties
57
   */
58
  public HotKeyCacheManager(HotKey hotKey, HotKeyProperties properties) {
2✔
59
    this.hotKey = hotKey;
3✔
60
    this.properties = properties;
3✔
61
  }
1✔
62

63
  /**
64
   * {@inheritDoc}
65
   *
66
   * <p>Returns the existing cache for the given name, or lazily creates and
67
   * registers one via {@link #getMissingCache(String)}. Creation is thread-safe
68
   * using double-checked locking.
69
   *
70
   * @param name the cache name
71
   * @return the cache instance, or {@code null} if creation fails
72
   */
73
  @Override
74
  public Cache getCache(@NonNull String name) {
75
    Cache cache = cacheMap.get(name);
6✔
76
    if (cache != null) {
2✔
77
      return cache;
2✔
78
    }
79
    return createAndRegisterCache(name);
4✔
80
  }
81

82
  private synchronized Cache createAndRegisterCache(String name) {
83
    Cache existing = cacheMap.get(name);
6✔
84
    if (existing != null) {
2!
UNCOV
85
      return existing;
×
86
    }
87

88
    Cache cache = getMissingCache(name);
4✔
89
    if (cache != null) {
2✔
90
      cacheMap.put(name, cache);
6✔
91
    }
92
    return cache;
2✔
93
  }
94

95
  /**
96
   * Create a new {@link HotKeySpringCache} for the given name. This method
97
   * is {@code protected} so that subclasses may override it to customize
98
   * cache creation.
99
   *
100
   * @param name the cache name
101
   * @return a new {@link HotKeySpringCache} that allows null values
102
   */
103
  protected Cache getMissingCache(String name) {
104
    return new HotKeySpringCache(name, hotKey, properties, true);
10✔
105
  }
106

107
  /**
108
   * {@inheritDoc}
109
   *
110
   * @return an unmodifiable view of the registered cache names
111
   */
112
  @Override
113
  @NonNull
114
  public Collection<String> getCacheNames() {
115
    return Collections.unmodifiableSet(cacheMap.keySet());
5✔
116
  }
117
}
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