Class UnboundedLocalCache<K,​V>

  • All Implemented Interfaces:
    LocalCache<K,​V>, java.util.concurrent.ConcurrentMap<K,​V>, java.util.Map<K,​V>

    final class UnboundedLocalCache<K,​V>
    extends java.lang.Object
    implements LocalCache<K,​V>
    An in-memory cache that has no capabilities for bounding the map. This implementation provides a lightweight wrapper on top of ConcurrentHashMap.
    • Field Detail

      • data

        final java.util.concurrent.ConcurrentHashMap<K,​V> data
      • isRecordingStats

        final boolean isRecordingStats
      • executor

        final java.util.concurrent.Executor executor
      • keySet

        transient java.util.Set<K> keySet
      • values

        transient java.util.Collection<V> values
      • entrySet

        transient java.util.Set<java.util.Map.Entry<K,​V>> entrySet
    • Constructor Detail

      • UnboundedLocalCache

        UnboundedLocalCache​(Caffeine<? super K,​? super V> builder,
                            boolean async)
    • Method Detail

      • hasWriteTime

        public boolean hasWriteTime()
        Description copied from interface: LocalCache
        Returns whether the cache captures the write time of the entry.
        Specified by:
        hasWriteTime in interface LocalCache<K,​V>
      • getIfPresent

        public V getIfPresent​(java.lang.Object key,
                              boolean recordStats)
        Description copied from interface: LocalCache
        See Cache.getIfPresent(Object). This method differs by accepting a parameter of whether to record the hit and miss statistics based on the success of this operation.
        Specified by:
        getIfPresent in interface LocalCache<K,​V>
      • getIfPresentQuietly

        public V getIfPresentQuietly​(java.lang.Object key,
                                     long[] writeTime)
        Description copied from interface: LocalCache
        See Cache.getIfPresent(Object). This method differs by not recording the access with the statistics nor the eviction policy, and populates the write time if known.
        Specified by:
        getIfPresentQuietly in interface LocalCache<K,​V>
      • hasRemovalListener

        public boolean hasRemovalListener()
        Description copied from interface: LocalCache
        Returns whether this cache notifies when an entry is removed.
        Specified by:
        hasRemovalListener in interface LocalCache<K,​V>
      • notifyRemoval

        public void notifyRemoval​(@Nullable
                                  K key,
                                  @Nullable
                                  V value,
                                  RemovalCause cause)
        Description copied from interface: LocalCache
        Asynchronously sends a removal notification to the listener.
        Specified by:
        notifyRemoval in interface LocalCache<K,​V>
      • isRecordingStats

        public boolean isRecordingStats()
        Description copied from interface: LocalCache
        Returns whether this cache has statistics enabled.
        Specified by:
        isRecordingStats in interface LocalCache<K,​V>
      • executor

        public java.util.concurrent.Executor executor()
        Description copied from interface: LocalCache
        Returns the Executor used by this cache.
        Specified by:
        executor in interface LocalCache<K,​V>
      • forEach

        public void forEach​(java.util.function.BiConsumer<? super K,​? super V> action)
        Specified by:
        forEach in interface java.util.concurrent.ConcurrentMap<K,​V>
        Specified by:
        forEach in interface java.util.Map<K,​V>
      • replaceAll

        public void replaceAll​(java.util.function.BiFunction<? super K,​? super V,​? extends V> function)
        Specified by:
        replaceAll in interface java.util.concurrent.ConcurrentMap<K,​V>
        Specified by:
        replaceAll in interface java.util.Map<K,​V>
      • computeIfAbsent

        public V computeIfAbsent​(K key,
                                 java.util.function.Function<? super K,​? extends V> mappingFunction,
                                 boolean recordStats,
                                 boolean recordLoad)
        Description copied from interface: LocalCache
        See ConcurrentMap.computeIfAbsent(K, java.util.function.Function<? super K, ? extends V>). This method differs by accepting parameters indicating how to record statistics.
        Specified by:
        computeIfAbsent in interface LocalCache<K,​V>
      • computeIfPresent

        public V computeIfPresent​(K key,
                                  java.util.function.BiFunction<? super K,​? super V,​? extends V> remappingFunction)
        Specified by:
        computeIfPresent in interface java.util.concurrent.ConcurrentMap<K,​V>
        Specified by:
        computeIfPresent in interface java.util.Map<K,​V>
      • compute

        public V compute​(K key,
                         java.util.function.BiFunction<? super K,​? super V,​? extends V> remappingFunction,
                         boolean recordMiss,
                         boolean recordLoad)
        Description copied from interface: LocalCache
        See ConcurrentMap.compute(K, java.util.function.BiFunction<? super K, ? super V, ? extends V>). This method differs by accepting parameters indicating whether to record miss and load statistics based on the success of this operation.
        Specified by:
        compute in interface LocalCache<K,​V>
      • merge

        public V merge​(K key,
                       V value,
                       java.util.function.BiFunction<? super V,​? super V,​? extends V> remappingFunction)
        Specified by:
        merge in interface java.util.concurrent.ConcurrentMap<K,​V>
        Specified by:
        merge in interface java.util.Map<K,​V>
      • remap

        V remap​(K key,
                java.util.function.BiFunction<? super K,​? super V,​? extends V> remappingFunction)
        A Map.compute(Object, BiFunction) that does not directly record any cache statistics.
        Parameters:
        key - key with which the specified value is to be associated
        remappingFunction - the function to compute a value
        Returns:
        the new value associated with the specified key, or null if none
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<K,​V>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<K,​V>
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<K,​V>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<K,​V>
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<K,​V>
      • get

        public V get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<K,​V>
      • put

        public V put​(K key,
                     V value)
        Specified by:
        put in interface java.util.Map<K,​V>
      • put

        public V put​(K key,
                     V value,
                     boolean notifyWriter)
        Description copied from interface: LocalCache
        See Cache.put(Object, Object). This method differs by allowing the operation to not notify the writer when an entry was inserted or updated.
        Specified by:
        put in interface LocalCache<K,​V>
      • putIfAbsent

        public V putIfAbsent​(K key,
                             V value)
        Specified by:
        putIfAbsent in interface java.util.concurrent.ConcurrentMap<K,​V>
        Specified by:
        putIfAbsent in interface java.util.Map<K,​V>
      • putAll

        public void putAll​(java.util.Map<? extends K,​? extends V> map)
        Specified by:
        putAll in interface java.util.Map<K,​V>
      • remove

        public V remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<K,​V>
      • remove

        public boolean remove​(java.lang.Object key,
                              java.lang.Object value)
        Specified by:
        remove in interface java.util.concurrent.ConcurrentMap<K,​V>
        Specified by:
        remove in interface java.util.Map<K,​V>
      • replace

        public V replace​(K key,
                         V value)
        Specified by:
        replace in interface java.util.concurrent.ConcurrentMap<K,​V>
        Specified by:
        replace in interface java.util.Map<K,​V>
      • replace

        public boolean replace​(K key,
                               V oldValue,
                               V newValue)
        Specified by:
        replace in interface java.util.concurrent.ConcurrentMap<K,​V>
        Specified by:
        replace in interface java.util.Map<K,​V>
      • equals

        public boolean equals​(java.lang.Object o)
        Specified by:
        equals in interface java.util.Map<K,​V>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Map<K,​V>
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • keySet

        public java.util.Set<K> keySet()
        Specified by:
        keySet in interface java.util.Map<K,​V>
      • values

        public java.util.Collection<V> values()
        Specified by:
        values in interface java.util.Map<K,​V>
      • entrySet

        public java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<K,​V>