Class ThreadCache


  • public class ThreadCache
    extends java.lang.Object
    An in-memory LRU cache store similar to MemoryLRUCache but byte-based, not record based
    • Constructor Summary

      Constructors 
      Constructor Description
      ThreadCache​(org.apache.kafka.common.utils.LogContext logContext, long maxCacheSizeBytes, StreamsMetricsImpl metrics)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addDirtyEntryFlushListener​(java.lang.String namespace, ThreadCache.DirtyEntryFlushListener listener)
      Add a listener that is called each time an entry is evicted from the cache or an explicit flush is called
      org.apache.kafka.streams.state.internals.ThreadCache.MemoryLRUCacheBytesIterator all​(java.lang.String namespace)  
      org.apache.kafka.streams.state.internals.LRUCacheEntry delete​(java.lang.String namespace, org.apache.kafka.common.utils.Bytes key)  
      long evicts()  
      void flush​(java.lang.String namespace)  
      long flushes()  
      org.apache.kafka.streams.state.internals.LRUCacheEntry get​(java.lang.String namespace, org.apache.kafka.common.utils.Bytes key)  
      long gets()  
      static java.lang.String nameSpaceFromTaskIdAndStore​(java.lang.String taskIDString, java.lang.String underlyingStoreName)
      The thread cache maintains a set of NamedCaches whose names are a concatenation of the task ID and the underlying store name.
      void put​(java.lang.String namespace, org.apache.kafka.common.utils.Bytes key, org.apache.kafka.streams.state.internals.LRUCacheEntry value)  
      void putAll​(java.lang.String namespace, java.util.List<KeyValue<org.apache.kafka.common.utils.Bytes,​org.apache.kafka.streams.state.internals.LRUCacheEntry>> entries)  
      org.apache.kafka.streams.state.internals.LRUCacheEntry putIfAbsent​(java.lang.String namespace, org.apache.kafka.common.utils.Bytes key, org.apache.kafka.streams.state.internals.LRUCacheEntry value)  
      long puts()  
      org.apache.kafka.streams.state.internals.ThreadCache.MemoryLRUCacheBytesIterator range​(java.lang.String namespace, org.apache.kafka.common.utils.Bytes from, org.apache.kafka.common.utils.Bytes to)  
      long size()  
      static java.lang.String taskIDfromCacheName​(java.lang.String cacheName)
      Given a cache name of the form taskid-storename, return the task ID.
      static java.lang.String underlyingStoreNamefromCacheName​(java.lang.String cacheName)
      Given a cache name of the form taskid-storename, return the store name.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ThreadCache

        public ThreadCache​(org.apache.kafka.common.utils.LogContext logContext,
                           long maxCacheSizeBytes,
                           StreamsMetricsImpl metrics)
    • Method Detail

      • puts

        public long puts()
      • gets

        public long gets()
      • evicts

        public long evicts()
      • flushes

        public long flushes()
      • nameSpaceFromTaskIdAndStore

        public static java.lang.String nameSpaceFromTaskIdAndStore​(java.lang.String taskIDString,
                                                                   java.lang.String underlyingStoreName)
        The thread cache maintains a set of NamedCaches whose names are a concatenation of the task ID and the underlying store name. This method creates those names.
        Parameters:
        taskIDString - Task ID
        underlyingStoreName - Underlying store name
        Returns:
      • taskIDfromCacheName

        public static java.lang.String taskIDfromCacheName​(java.lang.String cacheName)
        Given a cache name of the form taskid-storename, return the task ID.
        Parameters:
        cacheName -
        Returns:
      • underlyingStoreNamefromCacheName

        public static java.lang.String underlyingStoreNamefromCacheName​(java.lang.String cacheName)
        Given a cache name of the form taskid-storename, return the store name.
        Parameters:
        cacheName -
        Returns:
      • addDirtyEntryFlushListener

        public void addDirtyEntryFlushListener​(java.lang.String namespace,
                                               ThreadCache.DirtyEntryFlushListener listener)
        Add a listener that is called each time an entry is evicted from the cache or an explicit flush is called
        Parameters:
        namespace -
        listener -
      • flush

        public void flush​(java.lang.String namespace)
      • get

        public org.apache.kafka.streams.state.internals.LRUCacheEntry get​(java.lang.String namespace,
                                                                          org.apache.kafka.common.utils.Bytes key)
      • put

        public void put​(java.lang.String namespace,
                        org.apache.kafka.common.utils.Bytes key,
                        org.apache.kafka.streams.state.internals.LRUCacheEntry value)
      • putIfAbsent

        public org.apache.kafka.streams.state.internals.LRUCacheEntry putIfAbsent​(java.lang.String namespace,
                                                                                  org.apache.kafka.common.utils.Bytes key,
                                                                                  org.apache.kafka.streams.state.internals.LRUCacheEntry value)
      • putAll

        public void putAll​(java.lang.String namespace,
                           java.util.List<KeyValue<org.apache.kafka.common.utils.Bytes,​org.apache.kafka.streams.state.internals.LRUCacheEntry>> entries)
      • delete

        public org.apache.kafka.streams.state.internals.LRUCacheEntry delete​(java.lang.String namespace,
                                                                             org.apache.kafka.common.utils.Bytes key)
      • range

        public org.apache.kafka.streams.state.internals.ThreadCache.MemoryLRUCacheBytesIterator range​(java.lang.String namespace,
                                                                                                      org.apache.kafka.common.utils.Bytes from,
                                                                                                      org.apache.kafka.common.utils.Bytes to)
      • all

        public org.apache.kafka.streams.state.internals.ThreadCache.MemoryLRUCacheBytesIterator all​(java.lang.String namespace)
      • size

        public long size()