Class SoftCacheStorage

  • All Implemented Interfaces:
    CacheStorage, ConcurrentCacheStorage

    public class SoftCacheStorage
    extends Object
    implements ConcurrentCacheStorage
    Soft cache storage is a cache storage that uses SoftReference objects to hold the objects it was passed, therefore allows the garbage collector to purge the cache when it determines that it wants to free up memory. This class is thread-safe to the extent that its underlying map is. The default implementation uses a concurrent map on Java 5 and above, so it is thread-safe in that case.
    • Constructor Detail

      • SoftCacheStorage

        public SoftCacheStorage()
      • SoftCacheStorage

        public SoftCacheStorage​(Map backingMap)
    • Method Detail

      • isConcurrent

        public boolean isConcurrent()
        Description copied from interface: ConcurrentCacheStorage
        Returns true if this instance of cache storage is concurrently accessible from multiple threads without synchronization.
        Specified by:
        isConcurrent in interface ConcurrentCacheStorage
        Returns:
        true if this instance of cache storage is concurrently accessible from multiple threads without synchronization.
      • get

        public Object get​(Object key)
        Description copied from interface: CacheStorage
        Retrieve a cached value associated with a key
        Specified by:
        get in interface CacheStorage
        Parameters:
        key - the key for retrieving an associated value
        Returns:
        the cached value associated with the key, or null if no value is associated with the key.
      • put

        public void put​(Object key,
                        Object value)
        Description copied from interface: CacheStorage
        Associates a key with a cached value
        Specified by:
        put in interface CacheStorage
        Parameters:
        key - the key to associate with a value
        value - the value associated with the key.
      • remove

        public void remove​(Object key)
        Description copied from interface: CacheStorage
        Removes the value associated with a key, if it exists. If it doesn't exist, this method does nothing.
        Specified by:
        remove in interface CacheStorage
        Parameters:
        key - the key whose associated value is removed from the cache.
      • clear

        public void clear()
        Description copied from interface: CacheStorage
        Removes all values from this cache
        Specified by:
        clear in interface CacheStorage