Class BasicRasterServerCache

  • All Implemented Interfaces:
    MemoryCache

    public class BasicRasterServerCache
    extends BasicMemoryCache
    The BasicRasterServerCache is an implementation of the memory cache that is specific to store maximum possible cacheable items, until the heap size allows. Once the memory limit is hit, it will drop ALL cached items. Also, BasicRasterServerCache creates a pruner thread that removes all cached items which were not used for 20 seconds or more. The least recent use timeout is configurable via the setLeastRecentUseTimeout() method. In addition, the BasicRasterServerCache allocates 100MB memory and keeps only a phantom reference to the allocated 100M memory. Once any part of the application needs more memory the phantom referenced memory will be immediately released and the phantom reference will be added to the internal reference queue, which is monitored by an internal MemoryMonitorThread. Once the phantom reference is added to the reference queue, the entire cached content will be released. This approach allows to use almost entire available heap memory to cache rasters and release memory when more memory is needed to the application itself.
    • Field Detail

      • DEFAULT_INACCESSIBLE_MEMORY_SIZE

        protected static final int DEFAULT_INACCESSIBLE_MEMORY_SIZE
        See Also:
        Constant Field Values
      • DEFAULT_PRUNER_THREAD_TIMEOUT_MSEC

        protected static final long DEFAULT_PRUNER_THREAD_TIMEOUT_MSEC
        See Also:
        Constant Field Values
      • DEFAULT_LEAST_RECENTLY_USED_TIMEOUT_NSEC

        protected static final long DEFAULT_LEAST_RECENTLY_USED_TIMEOUT_NSEC
        See Also:
        Constant Field Values
      • inaccessibleMemorySize

        protected java.util.concurrent.atomic.AtomicInteger inaccessibleMemorySize
      • queue

        protected final java.lang.ref.ReferenceQueue<java.lang.Object> queue
      • lowMemorySemaphore

        protected java.lang.ref.Reference<java.lang.Object> lowMemorySemaphore
      • timeoutLeastRecentUseInNanoSeconds

        protected long timeoutLeastRecentUseInNanoSeconds
    • Constructor Detail

      • BasicRasterServerCache

        public BasicRasterServerCache()
        Constructs a new cache which uses entire memory, but will immediately drop all cached entries ones there is a need for more memory by anyone else.
      • BasicRasterServerCache

        public BasicRasterServerCache​(int inaccessibleMemorySize)
    • Method Detail

      • add

        public boolean add​(java.lang.Object key,
                           java.lang.Object clientObject,
                           long clientObjectSize)
        Description copied from class: BasicMemoryCache
        Adds an object to the cache. The add fails if the object or key is null, or if the size is zero, negative or greater than the maximmum capacity.
        Specified by:
        add in interface MemoryCache
        Overrides:
        add in class BasicMemoryCache
        Parameters:
        key - The unique reference key that identifies this object.
        clientObject - The actual object to be cached.
        clientObjectSize - The size of the object in cache units.
        Returns:
        returns true if clientObject was added, false otherwise.
      • updateMemorySemaphore

        protected void updateMemorySemaphore()
      • getLeastRecentUseTimeout

        public long getLeastRecentUseTimeout()
      • setLeastRecentUseTimeout

        public void setLeastRecentUseTimeout​(long nanoSeconds)
      • removeExpiredEntries

        protected void removeExpiredEntries()