Package waffle.util.cache
Interface Cache<K,V>
- Type Parameters:
K
- the type of keys maintained by this cacheV
- the type of mapped values
- All Known Implementing Classes:
CaffeineCache
public interface Cache<K,V>
A semi-persistent mapping from keys to values.
- Author:
- Simon Legner
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionFetches the key from the cachestatic <K,
V> Cache <K, V> newCache
(int timeout) Creates a new cache with the specified timeout.void
Stores a binding for the key and the value in the cachevoid
Removes the binding for the key from the cacheint
size()
Returns the number of bindings in this cache
-
Method Details
-
newCache
Creates a new cache with the specified timeout.The cache implementation is obtained using
ServiceLoader
. To create your own implementation, implementCacheSupplier
and register it using the/META-INF/services/waffle.util.cache.CacheSupplier
file on your classpath.- Type Parameters:
K
- the type of keys maintained by this cacheV
- the type of mapped values- Parameters:
timeout
- timeout in seconds- Returns:
- a new cache
- Throws:
NoSuchElementException
- if no cache can be instantiated, useThrowable.getSuppressed()
to obtain details.
-
get
Fetches the key from the cache- Parameters:
key
- the key- Returns:
- the corresponding value
- See Also:
-
put
Stores a binding for the key and the value in the cache- Parameters:
key
- the keyvalue
- the value- See Also:
-
remove
Removes the binding for the key from the cache- Parameters:
key
- the key- See Also:
-
size
int size()Returns the number of bindings in this cache- Returns:
- the size
- See Also:
-