gov.nasa.worldwind.cache
Class BasicRasterServerCache
java.lang.Object
gov.nasa.worldwind.cache.BasicMemoryCache
gov.nasa.worldwind.cache.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.
|
Constructor Summary |
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(int inaccessibleMemorySize)
|
| Methods inherited from class gov.nasa.worldwind.cache.BasicMemoryCache |
add, addCacheListener, clear, contains, finalize, getCapacity, getFreeCapacity, getLowWater, getName, getNumObjects, getObject, getUsedCapacity, remove, removeCacheListener, removeEntry, setCapacity, setLowWater, setName, toString |
DEFAULT_INACCESSIBLE_MEMORY_SIZE
protected static final int DEFAULT_INACCESSIBLE_MEMORY_SIZE
- 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
DEFAULT_PRUNER_THREAD_TIMEOUT_MSEC
protected static final long DEFAULT_PRUNER_THREAD_TIMEOUT_MSEC
- See Also:
- Constant Field Values
inaccessibleMemorySize
protected AtomicInteger inaccessibleMemorySize
lowMemorySemaphore
protected Reference<Object> lowMemorySemaphore
queue
protected final ReferenceQueue<Object> queue
timeoutLeastRecentUseInNanoSeconds
protected long timeoutLeastRecentUseInNanoSeconds
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)
add
public boolean add(Object key,
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.
getLeastRecentUseTimeout
public long getLeastRecentUseTimeout()
removeExpiredEntries
protected void removeExpiredEntries()
setLeastRecentUseTimeout
public void setLeastRecentUseTimeout(long nanoSeconds)
updateMemorySemaphore
protected void updateMemorySemaphore()