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 interface
MemoryCache.CacheListener
Provides the interface for cache clients to be notified of key events.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
add(java.lang.Object key, Cacheable clientObject)
Attempts to add theCacheable
object referenced by the key.boolean
add(java.lang.Object key, java.lang.Object clientObject, long objectSize)
Attempts to add the objectclientObject
, with sizeobjectSize
and referred to bykey
to the cache.void
addCacheListener(MemoryCache.CacheListener listener)
Adds a newcacheListener
, which will be sent notification whenever an entry is removed from the cache.void
clear()
Empties the cache.boolean
contains(java.lang.Object key)
Discovers whether or not this cache contains the object referenced bykey
.long
getCapacity()
Retrieves the maximum size of the cache.long
getFreeCapacity()
Retrieves the available space for storing new items.long
getLowWater()
Retrieves the low water value of theMemoryCache
.java.lang.String
getName()
int
getNumObjects()
Retrieve the number of items stored in theMemoryCache
.java.lang.Object
getObject(java.lang.Object key)
Retrieves the requested item from the cache.long
getUsedCapacity()
Retrieves the amount of usedMemoryCache
space.void
remove(java.lang.Object key)
Remove an object from the MemoryCache referenced bykey
.void
removeCacheListener(MemoryCache.CacheListener listener)
Removes aCacheListener
, notifications of events will no longer be sent to this listener.void
setCapacity(long capacity)
Sets the maximum capacity for thiscache
.void
setLowWater(long loWater)
Sets the new low water capacity value for thisMemoryCache
.void
setName(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 sizeobjectSize
and referred to bykey
to the cache.objectSize
is 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
synchronized
when 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 theCacheable
object 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
synchronized
when 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
- anObject
used to represent the item to remove.
-
getObject
java.lang.Object getObject(java.lang.Object key)
Retrieves the requested item from the cache. Ifkey
is null or the item is not found, this method returns null.- Parameters:
key
- anObject
used to represent the item to retrieve.- Returns:
- the requested
Object
if 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
synchronized
when it is implemented and should notify allCacheListener
s 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 usedMemoryCache
space. 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 aMemoryCache
runs 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 everyMemoryCache
necessarily 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 aMemoryCache
runs 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 everyMemoryCache
necessarily 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.
-
-