Class SoftMapCache


  • public class SoftMapCache
    extends Object
    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.
    • Constructor Detail

      • SoftMapCache

        public SoftMapCache​(boolean synched)
        Creates a new soft cache.
        Parameters:
        synched - true if the Map containing the values should by synchronized
    • Method Detail

      • get

        public Object get​(Object key)
        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

        public Object remove​(Object key)
        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
      • put

        public void put​(Object key,
                        Object value)
        Put a new value in the cache overwriting any existing value with the same key.
        Parameters:
        key - The key
        value - 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.