Overview | Package | Class | Use | Tree | Index | Help
| NASA World Wind
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## gov.nasa.worldwind
Interface MemoryCache

All Known Implementing Classes:
  BasicMemoryCache

    public interface MemoryCache

Nested Class Summary
`static interface` | `MemoryCache.CacheListener` Provides the interface for cache clients to be notified of key events.

Method Summary
`boolean` | `add(Object key, Cacheable clientObject)` Attempts to add the `Cacheable` object referenced by the key.
`boolean` | `add(Object key, Object clientObject, long objectSize)` Attempts to add the object `clientObject`, with size `objectSize` and referred to by `key` to the cache.
`void` | `addCacheListener(MemoryCache.CacheListener listener)` Adds a new `cacheListener`, which will be sent notification whenever an entry is removed from the cache.
`void` | `clear()` Empties the cache.
`boolean` | `contains(Object key)` Discovers whether or not this cache contains the object referenced by `key.`
`long` | `getCapacity()` Retrieves the maximum size of the cache in bytes.
`long` | `getFreeCapacity()` Retrieves the available space for storing new items.
`Set<Object>` | `getKeySet()` retrieve an unordered `Set` of the keys of the objects in this `MemoryCache`.
`long` | `getLowWater()` Retrieves the low water value of the `MemoryCache`.
`int` | `getNumObjects()` Retrieve the number of items stored in the `MemoryCache`.
`Object` | `getObject(Object key)` Retrieves the requested item from the cache.
`long` | `getUsedCapacity()` Retrieves the amount of used `MemoryCache` space.
`void` | `remove(Object key)` Remove an object from the MemoryCache referenced by `key`.
`void` | `removeCacheListener(MemoryCache.CacheListener listener)` Removes a `CacheListener`, notifications of events will no longer be sent to this listener.
`void` | `setCapacity(long capacity)` Sets the maximum capacity for this `cache` in bytes.
`void` | `setLowWater(long loWater)` Sets the new low water capacity value for this `MemoryCache`.

Method Detail

### add

    boolean add(Object key,
                Cacheable clientObject)

  Attempts to add the `Cacheable` 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` -
    `clientObject` -
  Returns:
    true if object was added, false otherwise
  See Also:
    `Cacheable`

### add

    boolean add(Object key,
                Object clientObject,
                long objectSize)

  Attempts to add the object `clientObject`, with size `objectSize` and referred to by `key` to the cache. `objectSize` is the size in bytes, 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 bytes.
  Returns:
    true if object was added, false otherwise

### addCacheListener

    void addCacheListener(MemoryCache.CacheListener listener)

  Adds a new `cacheListener`, which will be sent notification whenever an entry is removed from the cache.

  Parameters:
    `listener` - the new `MemoryCache.CacheListener`

### clear

    void clear()

  Empties the cache. After calling `clear()` on a `MemoryCache`, 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 all `CacheListener`s of entries removed.

### contains

    boolean contains(Object key)

  Discovers whether or not this cache contains the object referenced by `key. 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.

### getCapacity

    long getCapacity()

  Retrieves the maximum size of the cache in bytes.

  Returns:
    the maximum size of the `MemoryCache` in bytes.

### getFreeCapacity

    long getFreeCapacity()

  Retrieves the available space for storing new items.

  Returns:
    the long value of the remaining space for storing cached items.

### getKeySet

    Set<Object> getKeySet()

  retrieve an unordered `Set` of the keys of the objects in this `MemoryCache`.

  Returns:
    a `Set` containing all the keys in the cache.

### getLowWater

    long getLowWater()

  Retrieves the low water value of the `MemoryCache`. When a `MemoryCache` 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 every `MemoryCache` necessarily uses the low water system, so this may not return a useful value.

  Returns:
    the low water value of the `MemoryCache`.

### getNumObjects

    int getNumObjects()

  Retrieve the number of items stored in the `MemoryCache`.

  Returns:
    the number of items in the cache

### getObject

    Object getObject(Object key)

  Retrieves the requested item from the cache. If `key` is null or the item is not found, this method returns null.

  Parameters:
    `key` - an `Object` used to represent the item to retrieve
  Returns:
    the requested `Object` if found, null otherwise

### getUsedCapacity

    long getUsedCapacity()

  Retrieves the amount of used `MemoryCache` space. The value returned is in bytes.

  Returns:
    the long value of the number of bytes used by cached items.

### remove

    void remove(Object key)

  Remove an object from the MemoryCache referenced by `key`. If the object is already absent, this method simply returns without indicating the absence.

  Parameters:
    `key` - an `Object` used to represent the item to remove.

### removeCacheListener

    void removeCacheListener(MemoryCache.CacheListener listener)

  Removes a `CacheListener`, notifications of events will no longer be sent to this listener.

  Parameters:
    `listener` -

### setCapacity

    void setCapacity(long capacity)

  Sets the maximum capacity for this `cache` in bytes. This capacity has no impact on the number of items stored in the `MemoryCache`, 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 in bytes

### setLowWater

    void setLowWater(long loWater)

  Sets the new low water capacity value for this `MemoryCache`. When a `MemoryCache` 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 every `MemoryCache` 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 in bytes

Overview | Package | Class | Use | Tree | Index | Help
| NASA World Wind
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD