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

Hyshmily / hotkey / 28762732885

06 Jul 2026 01:49AM UTC coverage: 90.336% (-0.1%) from 90.457%
28762732885

push

github

Hyshmily
fix: fix known bugs

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

1314 of 1518 branches covered (86.56%)

Branch coverage included in aggregate %.

72 of 80 new or added lines in 9 files covered. (90.0%)

2 existing lines in 2 files now uncovered.

3715 of 4049 relevant lines covered (91.75%)

4.18 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.Internal;
20
import io.github.hyshmily.hotkey.autoconfigure.HotKeyProperties;
21
import java.util.Collection;
22
import java.util.Collections;
23
import java.util.concurrent.ConcurrentHashMap;
24
import java.util.concurrent.ConcurrentMap;
25
import org.jspecify.annotations.NonNull;
26
import org.springframework.cache.Cache;
27
import org.springframework.cache.CacheManager;
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
@Internal
47
public class HotKeyCacheManager implements CacheManager {
48

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

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

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

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

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

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

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