Top Description Methods
waffle.util.cache

public Interface Cache<K, V>

Known Direct Implementers
waffle.util.cache.CaffeineCache
Type Parameters
<K>
the type of keys maintained by this cache
<V>
the type of mapped values
Imports
java.util.NoSuchElementException, .ServiceLoader

A semi-persistent mapping from keys to values.
Author
Simon Legner
See Also
Can I provide a custom cache implementation?

Method Summary

Modifier and TypeMethod and Description
public V

Returns:

the corresponding value
get
(K
the key
key
)

Fetches the key from the cache

public static <
the type of keys maintained by this cache
K
,
the type of mapped values
V
>
Cache<K, V>

Returns:

a new cache
newCache
(int
timeout in seconds
timeout
)

Creates a new cache with the specified timeout.

public void
put(K
the key
key
,
V
the value
value
)

Stores a binding for the key and the value in the cache

public void
remove(K
the key
key
)

Removes the binding for the key from the cache

public int

Returns:

the size
size
()

Returns the number of bindings in this cache

Method Detail

getback to summary
public V get(K key)

Fetches the key from the cache

Parameters
key:K

the key

Returns:V

the corresponding value

See Also
java.util.Map#get
newCacheback to summary
public static <K, V> Cache<K, V> newCache(int timeout) throws NoSuchElementException

Creates a new cache with the specified timeout.

The cache implementation is obtained using ServiceLoader. To create your own implementation, implement CacheSupplier and register it using the /META-INF/services/waffle.util.cache.CacheSupplier file on your classpath.

Parameters
<K>
the type of keys maintained by this cache
<V>
the type of mapped values
timeout:int

timeout in seconds

Returns:Cache<K, V>

a new cache

Exceptions
NoSuchElementException:
if no cache can be instantiated, use Exception#getSuppressed() to obtain details.
putback to summary
public void put(K key, V value)

Stores a binding for the key and the value in the cache

Parameters
key:K

the key

value:V

the value

See Also
java.util.Map#put
removeback to summary
public void remove(K key)

Removes the binding for the key from the cache

Parameters
key:K

the key

See Also
java.util.Map#remove(Object)
sizeback to summary
public int size()

Returns the number of bindings in this cache

Returns:int

the size

See Also
java.util.Map#size