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 Object implements Cache<K,V>
A cache implementation that stores the information in memory.
The current implementation stores the values in memory in aWeakHashMap
.
-
-
Constructor Summary
Constructors Constructor Description InMemoryCache()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(K key)
ReturnsTrue
if the cache contains a entry with the key, orFalse
if there is none.static <expectedK,expectedV>
InMemoryCache<expectedK,expectedV>create()
Create a new instance for a cache in memory.Optional<V>
get(K key)
Returns the value associated withkey
in this cache, or empty if there is no cached value forkey
.boolean
isEmpty()
ReturnsTrue
if the cache is empty, orFalse
if there's at least a entry stored in cache.void
put(K key, V value)
Associates value with key in this cache.void
remove(K key)
Discards any cached value for this key.void
removeAll()
Discards all entries in the cache.long
size()
Returns the number of entries in this cache.
-
-
-
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:Cache
Associates 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 Optional<V> get(K key)
Description copied from interface:Cache
Returns the value associated withkey
in this cache, or empty if there is no cached value forkey
.
-
remove
public void remove(K key)
Description copied from interface:Cache
Discards any cached value for this key.
-
removeAll
public void removeAll()
Description copied from interface:Cache
Discards all entries in the cache.
-
contains
public boolean contains(K key)
Description copied from interface:Cache
ReturnsTrue
if the cache contains a entry with the key, orFalse
if there is none.
-
size
public long size()
Description copied from interface:Cache
Returns the number of entries in this cache.
-
-