public class BasicRasterServerCache extends BasicMemoryCache
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.BasicMemoryCache.CacheEntry
MemoryCache.CacheListener
Modifier and Type | Field and Description |
---|---|
protected static int |
DEFAULT_INACCESSIBLE_MEMORY_SIZE |
protected static long |
DEFAULT_LEAST_RECENTLY_USED_TIMEOUT_NSEC |
protected static long |
DEFAULT_PRUNER_THREAD_TIMEOUT_MSEC |
protected java.util.concurrent.atomic.AtomicInteger |
inaccessibleMemorySize |
protected java.lang.ref.Reference<java.lang.Object> |
lowMemorySemaphore |
protected java.lang.ref.ReferenceQueue<java.lang.Object> |
queue |
protected long |
timeoutLeastRecentUseInNanoSeconds |
capacity, currentUsedCapacity, entries, listeners, lock, lowWater, name
Constructor and Description |
---|
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) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(java.lang.Object key,
java.lang.Object clientObject,
long clientObjectSize)
Adds an object to the cache.
|
long |
getLeastRecentUseTimeout() |
protected void |
removeExpiredEntries() |
void |
setLeastRecentUseTimeout(long nanoSeconds) |
protected void |
updateMemorySemaphore() |
add, addCacheListener, clear, contains, finalize, getCapacity, getFreeCapacity, getLowWater, getName, getNumObjects, getObject, getUsedCapacity, remove, removeCacheListener, removeEntry, setCapacity, setLowWater, setName, toString
protected static final int DEFAULT_INACCESSIBLE_MEMORY_SIZE
protected static final long DEFAULT_LEAST_RECENTLY_USED_TIMEOUT_NSEC
protected static final long DEFAULT_PRUNER_THREAD_TIMEOUT_MSEC
protected java.util.concurrent.atomic.AtomicInteger inaccessibleMemorySize
protected java.lang.ref.Reference<java.lang.Object> lowMemorySemaphore
protected final java.lang.ref.ReferenceQueue<java.lang.Object> queue
protected long timeoutLeastRecentUseInNanoSeconds
public BasicRasterServerCache()
public BasicRasterServerCache(int inaccessibleMemorySize)
public boolean add(java.lang.Object key, java.lang.Object clientObject, long clientObjectSize)
BasicMemoryCache
add
in interface MemoryCache
add
in class BasicMemoryCache
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.public long getLeastRecentUseTimeout()
protected void removeExpiredEntries()
public void setLeastRecentUseTimeout(long nanoSeconds)
protected void updateMemorySemaphore()