Class SoftMapCache
java.lang.Object
org.apache.xmlgraphics.image.loader.util.SoftMapCache
Provides a simple cache using soft references and storing the values in a Map. The keys into
the Map are hard references, the values are referenced through soft references. The collected
values are cleaned up through a ReferenceQueue.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static org.apache.commons.logging.Log
loggerprivate Map
private ReferenceQueue
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
Checks the reference queue if any references have been cleared and removes them from the cache.void
clear()
Clears the cache.void
Triggers some house-keeping, i.e.Returns the value associated with the given key.private Object
getReference
(Object key, Reference ref) void
Put a new value in the cache overwriting any existing value with the same key.Removed the value associated with the given key.private Reference
wrapInReference
(Object obj, Object key)
-
Field Details
-
log
private static org.apache.commons.logging.Log loglogger -
map
-
refQueue
-
-
Constructor Details
-
SoftMapCache
public SoftMapCache(boolean synched) Creates a new soft cache.- Parameters:
synched
- true if the Map containing the values should by synchronized
-
-
Method Details
-
get
Returns the value associated with the given key. If the value is not found or the value has been collected, null is returned.- Parameters:
key
- the key- Returns:
- the requested value or null
-
remove
Removed the value associated with the given key. The value that is removed is returned as the methods result. If the value is not found or the value has been collected, null is returned.- Parameters:
key
- the key- Returns:
- the requested value or null
-
getReference
-
put
Put a new value in the cache overwriting any existing value with the same key.- Parameters:
key
- The keyvalue
- the value
-
clear
public void clear()Clears the cache. -
doHouseKeeping
public void doHouseKeeping()Triggers some house-keeping, i.e. processes any pending objects in the reference queue. -
wrapInReference
-
checkReferenceQueue
private void checkReferenceQueue()Checks the reference queue if any references have been cleared and removes them from the cache.
-