Package io.kcache
Interface Cache<K,V>
-
- All Superinterfaces:
AutoCloseable
,Closeable
,org.apache.kafka.common.Configurable
,Map<K,V>
,SortedMap<K,V>
- All Known Implementing Classes:
InMemoryBoundedCache
,InMemoryCache
,KafkaCache
,PersistentCache
,TransformedRawCache
public interface Cache<K,V> extends SortedMap<K,V>, org.apache.kafka.common.Configurable, Closeable
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description KeyValueIterator<K,V>
all()
Returns an iterator over all key-value pairs in this cache.default void
configure(Map<String,?> configs)
Configures the cache.Cache<K,V>
descendingCache()
Returns a reverse order view of the mappings contained in this cache.void
destroy()
Destroys the cache, if persistent.void
flush()
Flushes the cache.default SortedMap<K,V>
headMap(K toKey)
void
init()
Initializes the cache.default boolean
isPersistent()
Whether the cache is persistent.KeyValueIterator<K,V>
range(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)
Returns an iterator over the portion of this cache whose keys range fromfromKey
totoKey
.void
reset()
Resets the cache, clearing stale data before a sync.Cache<K,V>
subCache(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)
Returns a view of the portion of this cache whose keys range fromfromKey
totoKey
.default SortedMap<K,V>
subMap(K fromKey, K toKey)
void
sync()
Syncs (or re-initializes) the cache with the backing store.default SortedMap<K,V>
tailMap(K fromKey)
-
Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, equals, forEach, get, getOrDefault, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size
-
-
-
-
Method Detail
-
isPersistent
default boolean isPersistent()
Whether the cache is persistent.- Returns:
- whether the cache is persistent
-
configure
default void configure(Map<String,?> configs)
Configures the cache.- Specified by:
configure
in interfaceorg.apache.kafka.common.Configurable
-
init
void init() throws CacheInitializationException
Initializes the cache.- Throws:
CacheInitializationException
-
reset
void reset()
Resets the cache, clearing stale data before a sync. This can be used if the leader changes in a cluster.
-
sync
void sync()
Syncs (or re-initializes) the cache with the backing store.
-
subCache
Cache<K,V> subCache(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)
Returns a view of the portion of this cache whose keys range fromfromKey
totoKey
. IffromKey
andtoKey
are equal, the returned cache is empty unlessfromInclusive
andtoInclusive
are both true. The returned cache is backed by this cache, so changes in the returned cache are reflected in this cache, and vice-versa. The returned cache supports all optional cache operations that this cache supports.The returned cache will throw an
IllegalArgumentException
on an attempt to insert a key outside of its range, or to construct a subcache either of whose endpoints lie outside its range.- Parameters:
fromKey
- low endpoint of the keys in the returned cache;null
indicates the beginningfromInclusive
-true
if the low endpoint is to be included in the returned viewtoKey
- high endpoint of the keys in the returned cache;null
indicates the endtoInclusive
-true
if the high endpoint is to be included in the returned view- Returns:
- a view of the portion of this cache whose keys range from
fromKey
totoKey
- Throws:
ClassCastException
- iffromKey
andtoKey
cannot be compared to one another using this cache's comparator (or, if the cache has no comparator, using natural ordering). Implementations may, but are not required to, throw this exception iffromKey
ortoKey
cannot be compared to keys currently in the cache.IllegalArgumentException
- iffromKey
is greater thantoKey
; or if this cache itself has a restricted range, andfromKey
ortoKey
lies outside the bounds of the range
-
range
KeyValueIterator<K,V> range(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)
Returns an iterator over the portion of this cache whose keys range fromfromKey
totoKey
. IffromKey
andtoKey
are equal, the returned iterator is empty unlessfromInclusive
andtoInclusive
are both true.- Parameters:
fromKey
- low endpoint of the keys in the returned iterator;null
indicates the beginningfromInclusive
-true
if the low endpoint is to be included in the returned viewtoKey
- high endpoint of the keys in the returned iterator;null
indicates the endtoInclusive
-true
if the high endpoint is to be included in the returned view- Returns:
- an iterator over the portion of this cache whose keys range from
fromKey
totoKey
- Throws:
ClassCastException
- iffromKey
andtoKey
cannot be compared to one another using this cache's comparator (or, if the cache has no comparator, using natural ordering). Implementations may, but are not required to, throw this exception iffromKey
ortoKey
cannot be compared to keys currently in the cache.IllegalArgumentException
- iffromKey
is greater thantoKey
; or if this cache itself has a restricted range, andfromKey
ortoKey
lies outside the bounds of the range
-
all
KeyValueIterator<K,V> all()
Returns an iterator over all key-value pairs in this cache.- Returns:
- a
KeyValueIterator
over the elements in this collection
-
descendingCache
Cache<K,V> descendingCache()
Returns a reverse order view of the mappings contained in this cache. The descending cache is backed by this cache, so changes to the cache are reflected in the descending cache, and vice-versa. If either cache is modified while an iteration over a collection view of either cache is in progress (except through the iterator's ownremove
operation), the results of the iteration are undefined.- Returns:
- a reverse order view of this cache
-
flush
void flush()
Flushes the cache.
-
destroy
void destroy() throws IOException
Destroys the cache, if persistent.- Throws:
IOException
-
-