org.apache.commons.jexl3.internal
Class SoftCache<K,V>

java.lang.Object
  extended by org.apache.commons.jexl3.internal.SoftCache<K,V>
Type Parameters:
K - the cache key entry type
V - the cache key value type

public class SoftCache<K,V>
extends Object

A soft referenced cache.

The actual cache is held through a soft reference, allowing it to be GCed under memory pressure.


Method Summary
 void clear()
          Clears the cache.
<K,V> Map<K,V>
createCache(int cacheSize)
          Creates the cache store.
 List<Map.Entry<K,V>> entries()
          Produces the cache entry set.
 V get(K key)
          Gets a value from cache.
 void put(K key, V script)
          Puts a value in cache.
 int size()
          Returns the cache size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

size

public int size()
Returns the cache size.

Returns:
the cache size

clear

public void clear()
Clears the cache.


get

public V get(K key)
Gets a value from cache.

Parameters:
key - the cache entry key
Returns:
the cache entry value

put

public void put(K key,
                V script)
Puts a value in cache.

Parameters:
key - the cache entry key
script - the cache entry value

entries

public List<Map.Entry<K,V>> entries()
Produces the cache entry set.

For testing only, perform deep copy of cache entries

Returns:
the cache entry list

createCache

public <K,V> Map<K,V> createCache(int cacheSize)
Creates the cache store.

Type Parameters:
K - the key type
V - the value type
Parameters:
cacheSize - the cache size, must be > 0
Returns:
a Map usable as a cache bounded to the given size


Copyright © 2001–2017 The Apache Software Foundation. All rights reserved.