Class InMemoryCache<K,​V>

  • All Implemented Interfaces:
    Cache<K,​V>, Closeable, AutoCloseable, Map<K,​V>, SortedMap<K,​V>, org.apache.kafka.common.Configurable
    Direct Known Subclasses:
    InMemoryBoundedCache

    public class InMemoryCache<K,​V>
    extends com.google.common.collect.ForwardingSortedMap<K,​V>
    implements Cache<K,​V>
    In-memory cache
    • Constructor Detail

      • InMemoryCache

        public InMemoryCache()
      • InMemoryCache

        public InMemoryCache​(Comparator<? super K> comparator)
      • InMemoryCache

        public InMemoryCache​(NavigableMap<K,​V> delegate)
    • Method Detail

      • delegate

        protected SortedMap<K,​V> delegate()
        Specified by:
        delegate in class com.google.common.collect.ForwardingSortedMap<K,​V>
      • init

        public void init()
        Description copied from interface: Cache
        Initializes the cache.
        Specified by:
        init in interface Cache<K,​V>
      • reset

        public void reset()
        Description copied from interface: Cache
        Resets the cache, clearing stale data before a sync. This can be used if the leader changes in a cluster.
        Specified by:
        reset in interface Cache<K,​V>
      • sync

        public void sync()
        Description copied from interface: Cache
        Syncs (or re-initializes) the cache with the backing store.
        Specified by:
        sync in interface Cache<K,​V>
      • subCache

        public Cache<K,​V> subCache​(K from,
                                         boolean fromInclusive,
                                         K to,
                                         boolean toInclusive)
        Description copied from interface: Cache
        Returns a view of the portion of this cache whose keys range from fromKey to toKey. If fromKey and toKey are equal, the returned cache is empty unless fromInclusive and toInclusive 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.

        Specified by:
        subCache in interface Cache<K,​V>
        Parameters:
        from - low endpoint of the keys in the returned cache; null indicates the beginning
        fromInclusive - true if the low endpoint is to be included in the returned view
        to - high endpoint of the keys in the returned cache; null indicates the end
        toInclusive - 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 to toKey
      • range

        public KeyValueIterator<K,​V> range​(K from,
                                                 boolean fromInclusive,
                                                 K to,
                                                 boolean toInclusive)
        Description copied from interface: Cache
        Returns an iterator over the portion of this cache whose keys range from fromKey to toKey. If fromKey and toKey are equal, the returned iterator is empty unless fromInclusive and toInclusive are both true.
        Specified by:
        range in interface Cache<K,​V>
        Parameters:
        from - low endpoint of the keys in the returned iterator; null indicates the beginning
        fromInclusive - true if the low endpoint is to be included in the returned view
        to - high endpoint of the keys in the returned iterator; null indicates the end
        toInclusive - 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 to toKey
      • all

        public KeyValueIterator<K,​V> all()
        Description copied from interface: Cache
        Returns an iterator over all key-value pairs in this cache.
        Specified by:
        all in interface Cache<K,​V>
        Returns:
        a KeyValueIterator over the elements in this collection
      • descendingCache

        public Cache<K,​V> descendingCache()
        Description copied from interface: Cache
        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 own remove operation), the results of the iteration are undefined.
        Specified by:
        descendingCache in interface Cache<K,​V>
        Returns:
        a reverse order view of this cache
      • flush

        public void flush()
        Description copied from interface: Cache
        Flushes the cache.
        Specified by:
        flush in interface Cache<K,​V>
      • destroy

        public void destroy()
        Description copied from interface: Cache
        Destroys the cache, if persistent.
        Specified by:
        destroy in interface Cache<K,​V>