Class SoftCache<K,V,D>
java.lang.Object
com.ibm.icu.impl.CacheBase<K,V,D>
com.ibm.icu.impl.SoftCache<K,V,D>
- Type Parameters:
K- Cache lookup key typeV- Cache instance value type (must not be a CacheValue)D- Data type for creating a new instance value
- Direct Known Subclasses:
Calendar.WeekDataCache, ICUResourceBundleReader.ReaderCache, TimeZoneFormat.TimeZoneFormatCache, TimeZoneGenericNames.Cache, TimeZoneNames.Cache, TimeZoneNamesImpl.MZ2TZsCache, TimeZoneNamesImpl.TZ2MZsCache, ZoneMeta.CustomTimeZoneCache, ZoneMeta.SystemTimeZoneCache
Generic, thread-safe cache implementation, usually storing cached instances in
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.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal VgetInstance(K key, D data) Retrieves an instance from the cache.protected ConcurrentHashMap<K, Object> getMap()Methods inherited from class CacheBase
createInstance
-
Field Details
-
map
-
-
Constructor Details
-
SoftCache
public SoftCache()
-
-
Method Details
-
getMap
- Returns:
- the cache contents.
-
getInstance
Description copied from class:CacheBaseRetrieves 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.- Specified by:
getInstancein classCacheBase<K,V, D> - Parameters:
key- Cache lookup key for the requested instancedata- Data for createInstance() if the instance is not already cached- Returns:
- The requested instance
-