Class InMemoryCache<K,V>
- java.lang.Object
-
- com.github.javaparser.symbolsolver.cache.InMemoryCache<K,V>
-
- Type Parameters:
K- The type of the key.V- The type of the value.
- All Implemented Interfaces:
Cache<K,V>
public class InMemoryCache<K,V> extends java.lang.Object implements Cache<K,V>
A cache implementation that stores the information in memory.
The current implementation stores the values in memory in aWeakHashMap.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<K,V>mappedValues
-
Constructor Summary
Constructors Modifier Constructor Description privateInMemoryCache()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(K key)ReturnsTrueif the cache contains a entry with the key, orFalseif there is none.static <expectedK,expectedV>
InMemoryCache<expectedK,expectedV>create()Create a new instance for a cache in memory.java.util.Optional<V>get(K key)Returns the value associated withkeyin this cache, or empty if there is no cached value forkey.booleanisEmpty()ReturnsTrueif the cache is empty, orFalseif there's at least a entry stored in cache.voidput(K key, V value)Associates value with key in this cache.voidremove(K key)Discards any cached value for this key.voidremoveAll()Discards all entries in the cache.longsize()Returns the number of entries in this cache.CacheStatsstats()Returns a current snapshot of this cache's cumulative statistics, or a set of default values if the cache is not recording statistics.
-
-
-
Method Detail
-
create
public static <expectedK,expectedV> InMemoryCache<expectedK,expectedV> create()
Create a new instance for a cache in memory.- Type Parameters:
expectedK- The expected type for the key.expectedV- The expected type for the value.- Returns:
- A newly created instance of
InMemoryCache.
-
put
public void put(K key, V value)
Description copied from interface:CacheAssociates value with key in this cache.
If the cache previously contained a value associated with key, the old value is replaced by value.
-
get
public java.util.Optional<V> get(K key)
Description copied from interface:CacheReturns the value associated withkeyin this cache, or empty if there is no cached value forkey.
-
remove
public void remove(K key)
Description copied from interface:CacheDiscards any cached value for this key.
-
removeAll
public void removeAll()
Description copied from interface:CacheDiscards all entries in the cache.
-
contains
public boolean contains(K key)
Description copied from interface:CacheReturnsTrueif the cache contains a entry with the key, orFalseif there is none.
-
size
public long size()
Description copied from interface:CacheReturns the number of entries in this cache.
-
isEmpty
public boolean isEmpty()
Description copied from interface:CacheReturnsTrueif the cache is empty, orFalseif there's at least a entry stored in cache.
-
stats
public CacheStats stats()
Description copied from interface:CacheReturns a current snapshot of this cache's cumulative statistics, or a set of default values if the cache is not recording statistics. All statistics begin at zero and never decrease over the lifetime of the cache.
-
-