Top Description Fields Constructors Methods
com.ibm.icu.impl

public abstract Class SoftCache<K, V, D>

extends CacheBase<K, V, D>
Class Inheritance
Known Direct Subclasses
com.ibm.icu.text.TimeZoneFormat.TimeZoneFormatCache, com.ibm.icu.text.TimeZoneNames.Cache, com.ibm.icu.util.Calendar.WeekDataCache, com.ibm.icu.impl.ICUResourceBundleReader.ReaderCache, com.ibm.icu.impl.TimeZoneGenericNames.Cache, com.ibm.icu.impl.TimeZoneNamesImpl.TZ2MZsCache, com.ibm.icu.impl.TimeZoneNamesImpl.MZ2TZsCache, com.ibm.icu.impl.ZoneMeta.SystemTimeZoneCache, com.ibm.icu.impl.ZoneMeta.CustomTimeZoneCache
Type Parameters
<K>
Cache lookup key type
<V>
Cache instance value type (must not be a CacheValue)
<D>
Data type for creating a new instance value
Imports
java.util.concurrent.ConcurrentHashMap

Generic, thread-safe cache implementation, usually storing cached instances in java.lang.ref.References via CacheValues. To use, instantiate a subclass which implements the createInstance() method, and call get() with the key and the data. The get() call will use the data only if it needs to call createInstance(), otherwise the data is ignored.

When caching instances while the CacheValue "strength" is SOFT, the Java runtime can later release these instances once they are not used any more at all. If such an instance is then requested again, the getInstance() method will call createInstance() again and reset the CacheValue. The cache holds on to its map of keys to CacheValues forever.

A value can be null if createInstance() returns null. In this case, it must do so consistently for the same key and data.

Author
Markus Scherer, Mark Davis

Field Summary

Modifier and TypeField and Description
private ConcurrentHashMap<K, Object>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final V
getInstance(K
Cache lookup key for the requested instance
key
,
D
Data for createInstance() if the instance is not already cached
data
)

Implements abstract com.ibm.icu.impl.CacheBase.getInstance.

Retrieves an instance from the cache.
Inherited from com.ibm.icu.impl.CacheBase:
createInstance

Field Detail

mapback to summary
private ConcurrentHashMap<K, Object> map

Constructor Detail

SoftCacheback to summary
public SoftCache()

Method Detail

getInstanceback to summary
public final V getInstance(K key, D data)

Implements abstract com.ibm.icu.impl.CacheBase.getInstance.

Doc from com.ibm.icu.impl.CacheBase.getInstance.

Retrieves an instance from the cache. Calls createInstance(key, data) if the cache does not already contain an instance with this key. Ignores data if the cache already contains an instance with this key.

Parameters
key:K

Cache lookup key for the requested instance

data:D

Data for createInstance() if the instance is not already cached

Returns:V

The requested instance

Annotations
@SuppressWarnings:unchecked
@Override