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:
- Can I provide a custom cache implementation?
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description Vget(K key)Fetches the key from the cachestatic <K,V>
Cache<K,V>newCache(int timeout)Creates a new cache with the specified timeout.voidput(K key, V value)Stores a binding for the key and the value in the cachevoidremove(K key)Removes the binding for the key from the cacheintsize()Returns the number of bindings in this cache
-
-
-
Method Detail
-
newCache
static <K,V> Cache<K,V> newCache(int timeout) throws NoSuchElementException
Creates a new cache with the specified timeout. The cache implementation is obtained usingServiceLoader. To create your own implementation, implementCacheSupplierand register it using the/META-INF/services/waffle.util.cache.CacheSupplierfile 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
V get(K key)
Fetches the key from the cache- Parameters:
key- the key- Returns:
- the corresponding value
- See Also:
Map.get(java.lang.Object)
-
put
void put(K key, V value)
Stores a binding for the key and the value in the cache- Parameters:
key- the keyvalue- the value- See Also:
Map.put(K, V)
-
remove
void remove(K key)
Removes the binding for the key from the cache- Parameters:
key- the key- See Also:
Map.remove(Object)
-
size
int size()
Returns the number of bindings in this cache- Returns:
- the size
- See Also:
Map.size()
-
-