Class LocalCache<K,V>

java.lang.Object
java.util.AbstractMap<K,V>
com.google.common.cache.LocalCache<K,V>
All Implemented Interfaces:
ConcurrentMap<K,V>, Map<K,V>

class LocalCache<K,V> extends AbstractMap<K,V> implements ConcurrentMap<K,V>
The concurrent hash map implementation built by CacheBuilder.

This implementation is heavily derived from revision 1.96 of ConcurrentHashMap.java.

  • Field Details

    • MAXIMUM_CAPACITY

      static final int MAXIMUM_CAPACITY
      The maximum capacity, used if a higher value is implicitly specified by either of the constructors with arguments. MUST be a power of two <= 1<<30 to ensure that entries are indexable using ints.
      See Also:
    • MAX_SEGMENTS

      static final int MAX_SEGMENTS
      The maximum number of segments to allow; used to bound constructor arguments.
      See Also:
    • CONTAINS_VALUE_RETRIES

      static final int CONTAINS_VALUE_RETRIES
      Number of (unsynchronized) retries in the containsValue method.
      See Also:
    • DRAIN_THRESHOLD

      static final int DRAIN_THRESHOLD
      Number of cache access operations that can be buffered per segment before the cache's recency ordering information is updated. This is used to avoid lock contention by recording a memento of reads and delaying a lock acquisition until the threshold is crossed or a mutation occurs.

      This must be a (2^n)-1 as it is used as a mask.

      See Also:
    • DRAIN_MAX

      static final int DRAIN_MAX
      Maximum number of entries to be drained in a single cleanup run. This applies independently to the cleanup queue and both reference queues.
      See Also:
    • logger

      static final Logger logger
    • segmentMask

      final int segmentMask
      Mask value for indexing into segments. The upper bits of a key's hash code are used to choose the segment.
    • segmentShift

      final int segmentShift
      Shift value for indexing within segments. Helps prevent entries that end up in the same segment from also ending up in the same bucket.
    • segments

      final LocalCache.Segment<K,V>[] segments
      The segments, each of which is a specialized hash table.
    • concurrencyLevel

      final int concurrencyLevel
      The concurrency level.
    • keyEquivalence

      final Equivalence<Object> keyEquivalence
      Strategy for comparing keys.
    • valueEquivalence

      final Equivalence<Object> valueEquivalence
      Strategy for comparing values.
    • keyStrength

      final LocalCache.Strength keyStrength
      Strategy for referencing keys.
    • valueStrength

      final LocalCache.Strength valueStrength
      Strategy for referencing values.
    • maxWeight

      final long maxWeight
      The maximum weight of this map. UNSET_INT if there is no maximum.
    • weigher

      final Weigher<K,V> weigher
      Weigher to weigh cache entries.
    • expireAfterAccessNanos

      final long expireAfterAccessNanos
      How long after the last access to an entry the map will retain that entry.
    • expireAfterWriteNanos

      final long expireAfterWriteNanos
      How long after the last write to an entry the map will retain that entry.
    • refreshNanos

      final long refreshNanos
      How long after the last write an entry becomes a candidate for refresh.
    • removalNotificationQueue

      final Queue<RemovalNotification<K,V>> removalNotificationQueue
      Entries waiting to be consumed by the removal listener.
    • removalListener

      final RemovalListener<K,V> removalListener
      A listener that is invoked when an entry is removed due to expiration or garbage collection of soft/weak entries.
    • ticker

      final Ticker ticker
      Measures time in a testable way.
    • entryFactory

      final LocalCache.EntryFactory entryFactory
      Factory used to create new entries.
    • globalStatsCounter

      final AbstractCache.StatsCounter globalStatsCounter
      Accumulates global cache statistics. Note that there are also per-segments stats counters which must be aggregated to obtain a global stats view.
    • defaultLoader

      @CheckForNull final CacheLoader<? super K,V> defaultLoader
      The default cache loader to use on loading operations.
    • UNSET

      Placeholder. Indicates that the value hasn't been set yet.
    • DISCARDING_QUEUE

      static final Queue<?> DISCARDING_QUEUE
    • keySet

      @CheckForNull Set<K> keySet
    • values

      @CheckForNull Collection<V> values
    • entrySet

      @CheckForNull Set<Map.Entry<K,V>> entrySet
  • Constructor Details

    • LocalCache

      LocalCache(CacheBuilder<? super K,? super V> builder, @CheckForNull CacheLoader<? super K,V> loader)
      Creates a new, empty map with the specified strategy, initial capacity and concurrency level.
  • Method Details