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

Waffle / waffle / 6364

01 Feb 2026 02:07AM UTC coverage: 46.217%. Remained the same
6364

push

github

web-flow
Merge pull request #3206 from Waffle/renovate/checkstyle.version

Update dependency com.puppycrawl.tools:checkstyle to v13.1.0

276 of 734 branches covered (37.6%)

Branch coverage included in aggregate %.

1019 of 2068 relevant lines covered (49.27%)

1.0 hits per line

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

35.29
/Source/JNA/waffle-jna/src/main/java/waffle/util/cache/Cache.java
1
/*
2
 * SPDX-License-Identifier: MIT
3
 * See LICENSE file for details.
4
 *
5
 * Copyright 2010-2026 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
6
 */
7
package waffle.util.cache;
8

9
import java.util.NoSuchElementException;
10
import java.util.ServiceLoader;
11

12
import org.slf4j.Logger;
13
import org.slf4j.LoggerFactory;
14

15
/**
16
 * A semi-persistent mapping from keys to values.
17
 *
18
 * @param <K>
19
 *            the type of keys maintained by this cache
20
 * @param <V>
21
 *            the type of mapped values
22
 *
23
 * @see <a href="https://github.com/Waffle/waffle/blob/master/Docs/CustomCache.md">Can I provide a custom cache
24
 *      implementation?</a>
25
 */
26
public interface Cache<K, V> {
27

28
    /**
29
     * Creates a new cache with the specified timeout.
30
     * <p>
31
     * The cache implementation is obtained using {@link ServiceLoader}. To create your own implementation, implement
32
     * {@link CacheSupplier} and register it using the {@code /META-INF/services/waffle.util.cache.CacheSupplier} file
33
     * on your classpath.
34
     *
35
     * @param timeout
36
     *            timeout in seconds
37
     * @param <K>
38
     *            the type of keys maintained by this cache
39
     * @param <V>
40
     *            the type of mapped values
41
     *
42
     * @return a new cache
43
     *
44
     * @throws NoSuchElementException
45
     *             if no cache can be instantiated, use {@link Exception#getSuppressed()} to obtain details.
46
     */
47
    static <K, V> Cache<K, V> newCache(int timeout) throws NoSuchElementException {
48
        final NoSuchElementException exception = new NoSuchElementException();
2✔
49
        boolean cacheSupplierFound = false;
2✔
50
        for (CacheSupplier cacheSupplier : ServiceLoader.load(CacheSupplier.class)) {
2!
51
            cacheSupplierFound = true;
2✔
52
            try {
53
                return cacheSupplier.newCache(timeout);
2✔
54
            } catch (Exception e) {
×
55
                exception.addSuppressed(e);
×
56
            }
57
        }
×
58

59
        if (!cacheSupplierFound) {
×
60
            Logger logger = LoggerFactory.getLogger(Cache.class);
×
61
            logger.error(
×
62
                    "No CacheSupplier implementation found by ServiceLoader. Please see https://github.com/Waffle/waffle/blob/master/Docs/faq/CustomCache.md for possible solutions. Falling back to default CaffeineCache implementation.",
63
                    exception);
64
            return new CaffeineCache<>(timeout);
×
65
        }
66

67
        throw exception;
×
68
    }
69

70
    /**
71
     * Fetches the key from the cache.
72
     *
73
     * @param key
74
     *            the key
75
     *
76
     * @return the corresponding value
77
     *
78
     * @see java.util.Map#get
79
     */
80
    V get(K key);
81

82
    /**
83
     * Stores a binding for the key and the value in the cache.
84
     *
85
     * @param key
86
     *            the key
87
     * @param value
88
     *            the value
89
     *
90
     * @see java.util.Map#put
91
     */
92
    void put(K key, V value);
93

94
    /**
95
     * Removes the binding for the key from the cache.
96
     *
97
     * @param key
98
     *            the key
99
     *
100
     * @see java.util.Map#remove(Object)
101
     */
102
    void remove(K key);
103

104
    /**
105
     * Returns the number of bindings in this cache.
106
     *
107
     * @return the size
108
     *
109
     * @see java.util.Map#size
110
     */
111
    int size();
112
}
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