Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.slide.util
Class AbstractObjectCache

    java.lang.Object
      org.apache.slide.util.AbstractObjectCache

All Implemented Interfaces:
  ObjectCache

Direct Known Subclasses:
  HashMapObjectCache

public abstract class AbstractObjectCache
extends java.lang.Object
implements ObjectCache

Object cache abstract implementation.

Version:
  $Revision: 1.10 $ $Date: 2004/07/28 09:34:29 $

Field Summary
`protected double` | `cacheHits` Number of cache hits.
`protected double` | `cacheRequests` Number of cache requests.
`protected double` | `currentHitRatio` Current cache hit ratio.
`protected static double` | `DEFAULT_HIT_RATIO` Default desired hit ratio.
`protected static int` | `DEFAULT_SIZE` Default cache size.
`protected double` | `desiredHitRatio` Desired hit ratio.
`protected int` | `initialSize` Initial cache size.
`protected int` | `maxSize` Maximum cache size.

Constructor Summary
`AbstractObjectCache()` Constructor.
`AbstractObjectCache(int initialSize, int maxSize, double desiredHitRatio)` Constructor.

Method Summary
`abstract void` | `clear()` Clear object cache.
`abstract java.lang.Object` | `get(java.lang.Object key)` Get the object associated with the key.
`protected abstract int` | `getSize()` Get cache size.
`abstract void` | `put(java.lang.Object key, java.lang.Object value)` Add an object to the cache, or overwrite its value.
`abstract void` | `remove(java.lang.Object key)` Remove object associated with the given key.
`protected abstract void` | `removeSomeObjects()` Removes some elements from the cache.
`protected abstract void` | `resize()` Resize cache.
`protected void` | `shouldResize()` Is the cache size too small ?

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_SIZE

    protected static final int DEFAULT_SIZE

  Default cache size.

  See Also:
    Constant Field Values

### DEFAULT_HIT_RATIO

    protected static final double DEFAULT_HIT_RATIO

  Default desired hit ratio.

  See Also:
    Constant Field Values

### initialSize

    protected int initialSize

  Initial cache size.

### desiredHitRatio

    protected double desiredHitRatio

  Desired hit ratio.

### maxSize

    protected int maxSize

  Maximum cache size.

### cacheRequests

    protected double cacheRequests

  Number of cache requests.

### cacheHits

    protected double cacheHits

  Number of cache hits.

### currentHitRatio

    protected double currentHitRatio

  Current cache hit ratio. Equals to cacheHits / cacheRequests, if, and only if cacheRequests >= cache.size(). Otherwise, it's value is not used. If the cache hit ratio, is inferior to the desired hit ratio, the cache grows (unless its maximum size is already reached).

Constructor Detail

### AbstractObjectCache

    public AbstractObjectCache()

  Constructor.

  Warning (blinking) : That constructor is to be used really carefully as the cache maximum size is not limited.

### AbstractObjectCache

    public AbstractObjectCache(int initialSize,
                               int maxSize,
                               double desiredHitRatio)

  Constructor.

Parameters:
  `initialSize` - Initial size of the cache
  `maxSize` - Maximum size of the cache
  `desiredHitRatio` - Desired cache hit ratio

Method Detail

### get

    public abstract java.lang.Object get(java.lang.Object key)

  Get the object associated with the key.

  Specified by:
    `get` in interface `ObjectCache`
  Parameters:
    `key` - Object's key
  Returns:
    Object null if there is no object associated with that key in the cache, or the object value otherwise

### put

    public abstract void put(java.lang.Object key,
                             java.lang.Object value)

  Add an object to the cache, or overwrite its value.

  Specified by:
    `put` in interface `ObjectCache`
  Parameters:
    `key` - Object's key
    `value` - Object's value

### remove

    public abstract void remove(java.lang.Object key)

  Remove object associated with the given key. Doesn't do anything if the key wasn't associated with any object.

  Specified by:
    `remove` in interface `ObjectCache`
  Parameters:
    `key` - Object's key

### clear

    public abstract void clear()

  Clear object cache.

  Specified by:
    `clear` in interface `ObjectCache`

### removeSomeObjects

    protected abstract void removeSomeObjects()

  Removes some elements from the cache. The selection of the objects to remove, along with the number are left to the implementation.

### getSize

    protected abstract int getSize()

  Get cache size.

  Returns:
    int Current cache size

### resize

    protected abstract void resize()

  Resize cache.

### shouldResize

    protected void shouldResize()

  Is the cache size too small ?

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD