Package gov.nasa.worldwind.cache
Interface MemoryCache
-
- All Known Implementing Classes:
BasicMemoryCache,BasicRasterServerCache
public interface MemoryCache
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceMemoryCache.CacheListenerProvides the interface for cache clients to be notified of key events.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanadd(java.lang.Object key, Cacheable clientObject)Attempts to add theCacheableobject referenced by the key.booleanadd(java.lang.Object key, java.lang.Object clientObject, long objectSize)Attempts to add the objectclientObject, with sizeobjectSizeand referred to bykeyto the cache.voidaddCacheListener(MemoryCache.CacheListener listener)Adds a newcacheListener, which will be sent notification whenever an entry is removed from the cache.voidclear()Empties the cache.booleancontains(java.lang.Object key)Discovers whether or not this cache contains the object referenced bykey.longgetCapacity()Retrieves the maximum size of the cache.longgetFreeCapacity()Retrieves the available space for storing new items.longgetLowWater()Retrieves the low water value of theMemoryCache.java.lang.StringgetName()intgetNumObjects()Retrieve the number of items stored in theMemoryCache.java.lang.ObjectgetObject(java.lang.Object key)Retrieves the requested item from the cache.longgetUsedCapacity()Retrieves the amount of usedMemoryCachespace.voidremove(java.lang.Object key)Remove an object from the MemoryCache referenced bykey.voidremoveCacheListener(MemoryCache.CacheListener listener)Removes aCacheListener, notifications of events will no longer be sent to this listener.voidsetCapacity(long capacity)Sets the maximum capacity for thiscache.voidsetLowWater(long loWater)Sets the new low water capacity value for thisMemoryCache.voidsetName(java.lang.String name)
-
-
-
Method Detail
-
setName
void setName(java.lang.String name)
-
getName
java.lang.String getName()
-
addCacheListener
void addCacheListener(MemoryCache.CacheListener listener)
Adds a newcacheListener, which will be sent notification whenever an entry is removed from the cache.- Parameters:
listener- the newMemoryCache.CacheListener
-
removeCacheListener
void removeCacheListener(MemoryCache.CacheListener listener)
Removes aCacheListener, notifications of events will no longer be sent to this listener.- Parameters:
listener- the cache listener to remove.
-
contains
boolean contains(java.lang.Object key)
Discovers whether or not this cache contains the object referenced bykey. Currently no interface exists to discover if an object resides in the cache by referencing itself.- Parameters:
key- the key which the object is referenced by.- Returns:
- true if the key is found in the cache, false otherwise.
-
add
boolean add(java.lang.Object key, java.lang.Object clientObject, long objectSize)Attempts to add the objectclientObject, with sizeobjectSizeand referred to bykeyto the cache.objectSizeis the size in cache units, but is not checked for accuracy. Returns whether or not the add was successful.Note that the size passed in may be used, rather than the real size of the object. In some implementations, the accuracy of the space used calls will depend on the collection of these sizes, rather than actual size.
This method should be declared
synchronizedwhen it is implemented.- Parameters:
key- an object used to reference the cached item.clientObject- the item to be cached.objectSize- the size of the item in cache units.- Returns:
- true if object was added, false otherwise.
-
add
boolean add(java.lang.Object key, Cacheable clientObject)Attempts to add theCacheableobject referenced by the key. No explicit size value is required as this method queries the Cacheable to discover the size.This method should be declared
synchronizedwhen it is implemented.- Parameters:
key- an object used to reference the cached item.clientObject- the item to be cached.- Returns:
- true if object was added, false otherwise.
- See Also:
Cacheable
-
remove
void remove(java.lang.Object key)
Remove an object from the MemoryCache referenced bykey. If the object is already absent, this method simply returns without indicating the absence.- Parameters:
key- anObjectused to represent the item to remove.
-
getObject
java.lang.Object getObject(java.lang.Object key)
Retrieves the requested item from the cache. Ifkeyis null or the item is not found, this method returns null.- Parameters:
key- anObjectused to represent the item to retrieve.- Returns:
- the requested
Objectif found, null otherwise.
-
clear
void clear()
Empties the cache. After callingclear()on aMemoryCache, calls relating to used capacity and number of items should return zero and the free capacity should be the maximum capacity.This method should be declared
synchronizedwhen it is implemented and should notify allCacheListeners of entries removed.
-
getNumObjects
int getNumObjects()
Retrieve the number of items stored in theMemoryCache.- Returns:
- the number of items in the cache.
-
getCapacity
long getCapacity()
Retrieves the maximum size of the cache.- Returns:
- the maximum size of the
MemoryCache.
-
getUsedCapacity
long getUsedCapacity()
Retrieves the amount of usedMemoryCachespace. The value returned is in cache units.- Returns:
- the long value of the number of cache units used by cached items.
-
getFreeCapacity
long getFreeCapacity()
Retrieves the available space for storing new items.- Returns:
- the long value of the remaining space for storing cached items.
-
getLowWater
long getLowWater()
Retrieves the low water value of theMemoryCache. When aMemoryCacheruns out of free space, it must remove some items if it wishes to add any more. It continues removing items until the low water level is reached. Not everyMemoryCachenecessarily uses the low water system, so this may not return a useful value.- Returns:
- the low water value of the
MemoryCache.
-
setLowWater
void setLowWater(long loWater)
Sets the new low water capacity value for thisMemoryCache. When aMemoryCacheruns out of free space, it must remove some items if it wishes to add any more. It continues removing items until the low water level is reached. Not everyMemoryCachenecessarily uses the low water system, so this method may not have any actual effect in some implementations.- Parameters:
loWater- the new low water value.
-
setCapacity
void setCapacity(long capacity)
Sets the maximum capacity for thiscache. This capacity has no impact on the number of items stored in theMemoryCache, except that every item must have a positive size. Generally the used capacity is the total of the sizes of all stored items.- Parameters:
capacity- the new capacity.
-
-