Class SoftCache<K,V>
java.lang.Object
org.apache.commons.jexl3.internal.SoftCache<K,V>
- Type Parameters:
K
- the cache key entry typeV
- the cache key value type
A soft referenced cache.
The actual cache is held through a soft reference, allowing it to be GCed under memory pressure.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final float
The default cache load factor.private final ReadWriteLock
The cache r/w lock.private SoftReference<Map<K,
V>> The soft reference to the cache map.private final int
The cache size. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the cache.<K,
V> Map<K, V> createCache
(int cacheSize) Creates the cache store.entries()
Produces the cache entry set.Gets a value from cache.void
Puts a value in cache.int
size()
Returns the cache size.
-
Field Details
-
LOAD_FACTOR
private static final float LOAD_FACTORThe default cache load factor.- See Also:
-
size
private final int sizeThe cache size. -
ref
The soft reference to the cache map. -
lock
The cache r/w lock.
-
-
Constructor Details
-
SoftCache
SoftCache(int theSize) Creates a new instance of a soft cache.- Parameters:
theSize
- the cache size
-
-
Method Details
-
size
public int size()Returns the cache size.- Returns:
- the cache size
-
clear
public void clear()Clears the cache. -
get
Gets a value from cache.- Parameters:
key
- the cache entry key- Returns:
- the cache entry value
-
put
Puts a value in cache.- Parameters:
key
- the cache entry keyscript
- the cache entry value
-
entries
Produces the cache entry set.For testing only, perform deep copy of cache entries
- Returns:
- the cache entry list
-
createCache
Creates the cache store.- Type Parameters:
K
- the key typeV
- the value type- Parameters:
cacheSize
- the cache size, must be > 0- Returns:
- a Map usable as a cache bounded to the given size
-