Top Description Inners Fields Constructors Methods
com.google.common.cache

pack-priv Class LocalCache<K, V>

extends AbstractMap<K, V>
implements ConcurrentMap<K, V>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.ConcurrentMap, java.util.Map
Annotations
@SuppressWarnings:GoodTime, nullness
@GwtCompatible
emulated:true
Static Imports
com.google.common.base.Preconditions.checkNotNull, .Preconditions.checkState, com.google.common.cache.CacheBuilder.NULL_TICKER, .CacheBuilder.UNSET_INT, com.google.common.util.concurrent.Futures.transform, .MoreExecutors.directExecutor, .Uninterruptibles.getUninterruptibly, java.util.Collections.unmodifiableSet, java.util.concurrent.TimeUnit.NANOSECONDS

The concurrent hash map implementation built by CacheBuilder.

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

Authors
Charles Fry, Bob Lee (com.google.common.collect.MapMaker), Doug Lea (ConcurrentHashMap)

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv abstract class
pack-priv abstract static class
pack-priv static class
LocalCache.AccessQueue<K, V>

A custom queue for managing access order.

pack-priv static class
pack-priv static enum
LocalCache.EntryFactory

Creates new entries.

pack-priv class
pack-priv class
pack-priv abstract class
pack-priv class
pack-priv class
pack-priv static class
LocalCache.LoadingSerializationProxy<K, V>

Serializes the configuration of a LocalCache, reconstituting it as an LoadingCache using CacheBuilder upon deserialization.

pack-priv static class
pack-priv static class
pack-priv static class
pack-priv static class
LocalCache.ManualSerializationProxy<K, V>

Serializes the configuration of a LocalCache, reconstituting it as a Cache using CacheBuilder upon deserialization.

private static enum
pack-priv static class
LocalCache.Segment<K, V>

Segments are specialized versions of hash tables.

pack-priv static class
LocalCache.SoftValueReference<K, V>

References a soft value.

pack-priv static enum
pack-priv static class
pack-priv static class
pack-priv static class
LocalCache.StrongEntry<K, V>

Used for strongly-referenced keys.

pack-priv static class
LocalCache.StrongValueReference<K, V>

References a strong value.

pack-priv static class
pack-priv class
pack-priv static interface
LocalCache.ValueReference<K, V>

A reference to a value.

pack-priv class
pack-priv static class
pack-priv static class
pack-priv static class
LocalCache.WeakEntry<K, V>

Used for weakly-referenced keys.

pack-priv static class
LocalCache.WeakValueReference<K, V>

References a weak value.

pack-priv static class
pack-priv static class
LocalCache.WeightedSoftValueReference<K, V>

References a soft value.

pack-priv static class
LocalCache.WeightedStrongValueReference<K, V>

References a strong value.

pack-priv static class
LocalCache.WeightedWeakValueReference<K, V>

References a weak value.

pack-priv static class
LocalCache.WriteQueue<K, V>

A custom queue for managing eviction order.

pack-priv class
LocalCache.WriteThroughEntry

Custom Entry class used by EntryIterator.next(), that relays setValue changes to the underlying map.

Field Summary

Modifier and TypeField and Description
pack-priv final int
concurrencyLevel

The concurrency level.

pack-priv static final int
CONTAINS_VALUE_RETRIES

Number of (unsynchronized) retries in the containsValue method.

pack-priv final CacheLoader<? super K, V>
defaultLoader

The default cache loader to use on loading operations.

pack-priv static final Queue<?>
pack-priv static final int
DRAIN_MAX

Maximum number of entries to be drained in a single cleanup run.

pack-priv 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.

pack-priv final LocalCache.EntryFactory
entryFactory

Factory used to create new entries.

pack-priv Set<Map.Entry<K, V>>
pack-priv final long
expireAfterAccessNanos

How long after the last access to an entry the map will retain that entry.

pack-priv final long
expireAfterWriteNanos

How long after the last write to an entry the map will retain that entry.

pack-priv final AbstractCache.StatsCounter
globalStatsCounter

Accumulates global cache statistics.

pack-priv final Equivalence<Object>
keyEquivalence

Strategy for comparing keys.

pack-priv Set<K>
pack-priv final LocalCache.Strength
keyStrength

Strategy for referencing keys.

pack-priv static final Logger
pack-priv static final int
MAX_SEGMENTS

The maximum number of segments to allow; used to bound constructor arguments.

pack-priv static final int
MAXIMUM_CAPACITY

The maximum capacity, used if a higher value is implicitly specified by either of the constructors with arguments.

pack-priv final long
maxWeight

The maximum weight of this map.

pack-priv final long
refreshNanos

How long after the last write an entry becomes a candidate for refresh.

pack-priv 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.

pack-priv final Queue<RemovalNotification<K, V>>
removalNotificationQueue

Entries waiting to be consumed by the removal listener.

pack-priv final int
segmentMask

Mask value for indexing into segments.

pack-priv final LocalCache.Segment<K, V>[]
segments

The segments, each of which is a specialized hash table.

pack-priv final int
segmentShift

Shift value for indexing within segments.

pack-priv final Ticker
ticker

Measures time in a testable way.

pack-priv static final LocalCache.ValueReference<Object, Object>
UNSET

Placeholder.

pack-priv final Equivalence<Object>
valueEquivalence

Strategy for comparing values.

pack-priv Collection<V>
pack-priv final LocalCache.Strength
valueStrength

Strategy for referencing values.

pack-priv final Weigher<K, V>
weigher

Weigher to weigh cache entries.

Constructor Summary

AccessConstructor and Description
pack-priv
LocalCache(CacheBuilder<? super K, ? super V> builder, CacheLoader<? super K, V> loader)

Creates a new, empty map with the specified strategy, initial capacity and concurrency level.

Method Summary

Modifier and TypeMethod and Description
public void
public void
clear()

Overrides java.util.AbstractMap.clear.

Implements java.util.Map.clear.

Removes all of the mappings from this map (optional operation).
public V
compute(K
key with which the specified value is to be associated
key
,
BiFunction<? super K, ? super @Nullable V, ? extends V>
the remapping function to compute a value
function
)

Overrides default java.util.concurrent.ConcurrentMap.compute, java.util.Map.compute.

Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).
public V
computeIfAbsent(K
key with which the specified value is to be associated
key
,
Function<? super K, ? extends V>
the mapping function to compute a value
function
)

Overrides default java.util.concurrent.ConcurrentMap.computeIfAbsent, java.util.Map.computeIfAbsent.

If the specified key is not already associated with a value (or is mapped to null), attempts to compute its value using the given mapping function and enters it into this map unless null.
public V
computeIfPresent(K
key with which the specified value is to be associated
key
,
BiFunction<? super K, ? super V, ? extends V>
the remapping function to compute a value
function
)

Overrides default java.util.concurrent.ConcurrentMap.computeIfPresent, java.util.Map.computeIfPresent.

If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value.
pack-priv static <K, V> void
connectAccessOrder(ReferenceEntry<K, V> previous, ReferenceEntry<K, V> next)

pack-priv static <K, V> void
connectWriteOrder(ReferenceEntry<K, V> previous, ReferenceEntry<K, V> next)

public boolean
containsKey(Object
key whose presence in this map is to be tested
key
)

Overrides java.util.AbstractMap.containsKey.

Implements java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.
public boolean
containsValue(Object
value whose presence in this map is to be tested
value
)

Overrides java.util.AbstractMap.containsValue.

Implements java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value.
pack-priv ReferenceEntry<K, V>
copyEntry(ReferenceEntry<K, V> original, ReferenceEntry<K, V> newNext)

This method is a convenience for testing.

pack-priv LocalCache.Segment<K, V>
createSegment(int initialCapacity, long maxSegmentWeight, AbstractCache.StatsCounter statsCounter)

pack-priv boolean
pack-priv static <E> Queue<E>
discardingQueue()

Queue that discards all elements.

public Set<Map.Entry<K, V>>
entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.
pack-priv boolean
pack-priv boolean
pack-priv boolean
pack-priv boolean
public V
get(Object
the key whose associated value is to be returned
key
)

Overrides java.util.AbstractMap.get.

Implements java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
pack-priv V
get(K key, CacheLoader<? super K, V> loader)

pack-priv ImmutableMap<K, V>
getAll(Iterable<? extends K> keys)

pack-priv ImmutableMap<K, V>
pack-priv ReferenceEntry<K, V>
getEntry(Object key)

Returns the internal entry for the specified key.

public V
pack-priv V
getLiveValue(ReferenceEntry<K, V> entry, long now)

Gets the value from an entry.

public V
getOrDefault(Object
the key whose associated value is to be returned
key
,
V
the default mapping of the key
defaultValue
)

Overrides default java.util.concurrent.ConcurrentMap.getOrDefault, java.util.Map.getOrDefault.

Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.
pack-priv V
getOrLoad(K key)

pack-priv int
hash(Object key)

pack-priv void
public boolean
isEmpty()

Overrides java.util.AbstractMap.isEmpty.

Implements java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.
pack-priv boolean
isExpired(ReferenceEntry<K, V> entry, long now)

Returns true if the entry has expired.

pack-priv boolean
isLive(ReferenceEntry<K, V> entry, long now)

This method is a convenience for testing.

public Set<K>
keySet()

Overrides java.util.AbstractMap.keySet.

Implements java.util.Map.keySet.

Returns a Set view of the keys contained in this map.
pack-priv Map<K, V>
loadAll(Set<? extends K> keys, CacheLoader<? super K, V> loader)

Returns the result of calling CacheLoader#loadAll, or null if loader doesn't implement loadAll.

pack-priv long
public V
merge(K
key with which the resulting value is to be associated
key
,
V
the non-null value to be merged with the existing value associated with the key or, if no existing value or a null value is associated with the key, to be associated with the key
newValue
,
BiFunction<? super V, ? super V, ? extends @Nullable V>
the remapping function to recompute a value if present
function
)

Overrides default java.util.concurrent.ConcurrentMap.merge, java.util.Map.merge.

If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value.
pack-priv ReferenceEntry<K, V>
newEntry(K key, int hash, ReferenceEntry<K, V> next)

This method is a convenience for testing.

pack-priv final LocalCache.Segment<K, V>[]
newSegmentArray(int ssize)

pack-priv LocalCache.ValueReference<K, V>
newValueReference(ReferenceEntry<K, V> entry, V value, int weight)

This method is a convenience for testing.

pack-priv static <K, V> ReferenceEntry<K, V>
pack-priv static <K, V> void
pack-priv static <K, V> void
pack-priv void
processPendingNotifications()

Notifies listeners that an entry has been automatically removed due to expiration, eviction, or eligibility for garbage collection.

public V
put(K
key with which the specified value is to be associated
key
,
V
value to be associated with the specified key
value
)

Overrides java.util.AbstractMap.put.

Implements java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation).
public void
putAll(Map<? extends K, ? extends V>
mappings to be stored in this map
m
)

Overrides java.util.AbstractMap.putAll.

Implements java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation).
public V
putIfAbsent(K
key with which the specified value is to be associated
key
,
V
value to be associated with the specified key
value
)

Overrides default java.util.Map.putIfAbsent.

Implements java.util.concurrent.ConcurrentMap.putIfAbsent.

If the specified key is not already associated with a value, associates it with the given value.
pack-priv void
pack-priv void
reclaimValue(LocalCache.ValueReference<K, V> valueReference)

pack-priv boolean
pack-priv boolean
pack-priv boolean
pack-priv void
refresh(K key)

pack-priv boolean
pack-priv static int
rehash(int
hash code
h
)

Applies a supplemental hash function to a given hash code, which defends against poor quality hash functions.

public V
remove(Object
key whose mapping is to be removed from the map
key
)

Overrides java.util.AbstractMap.remove.

Implements java.util.Map.remove.

Removes the mapping for a key from this map if it is present (optional operation).
public boolean
remove(Object
key with which the specified value is associated
key
,
Object
value expected to be associated with the specified key
value
)

Overrides default java.util.Map.remove.

Implements java.util.concurrent.ConcurrentMap.remove.

Removes the entry for a key only if currently mapped to a given value.
pack-priv boolean
removeIf(BiPredicate<? super K, ? super V> filter)

public boolean
replace(K
key with which the specified value is associated
key
,
V
value expected to be associated with the specified key
oldValue
,
V
value to be associated with the specified key
newValue
)

Overrides default java.util.Map.replace.

Implements java.util.concurrent.ConcurrentMap.replace.

Replaces the entry for a key only if currently mapped to a given value.
public V
replace(K
key with which the specified value is associated
key
,
V
value to be associated with the specified key
value
)

Overrides default java.util.Map.replace.

Implements java.util.concurrent.ConcurrentMap.replace.

Replaces the entry for a key only if currently mapped to some value.
pack-priv LocalCache.Segment<K, V>

Returns:

the segment
segmentFor
(int
the hash code for the key
hash
)

Returns the segment that should be used for a key with the given hash.

public int
size()

Overrides java.util.AbstractMap.size.

Implements java.util.Map.size.

Returns the number of key-value mappings in this map.
private static <E> ArrayList<E>
pack-priv static <K, V> LocalCache.ValueReference<K, V>
unset()

Singleton placeholder that indicates a value is being loaded.

pack-priv boolean
pack-priv boolean
pack-priv boolean
pack-priv boolean
pack-priv boolean
pack-priv boolean
public Collection<V>
values()

Overrides java.util.AbstractMap.values.

Implements java.util.Map.values.

Returns a Collection view of the values contained in this map.
Inherited from java.util.AbstractMap:
cloneequalshashCodetoString