Package helma.util

# Class CacheMap

java.lang.Object
helma.util.CacheMap

All Implemented Interfaces:
  `ObjectCache`

Direct Known Subclasses:
  `WeakCacheMap`

public class CacheMap extends Object implements ObjectCache

## Constructor Summary

Constructors
Constructor
Description
`CacheMap()`
Zero argument constructor.
`CacheMap(int initialCapacity)`
`CacheMap(int initialCapacity, float loadFactor)`

## Method Summary

Modifier and Type
Method
Description
`boolean`
`clear()`
Removes all items currently stored in the cache.
`boolean`
`containsKey(Object key)`
Returns true if the collection contains an element for the key.
`int`
`containsKeys(Object[] keys)`
Returns the number of keys in object array `keys` that were not found in the Map.
`boolean`
`containsValue(Object value)`
`protected Map`
`createTable(int capacity, float loadFactor)`
Override this method to use custom Map implementations.
`Object`
`get(Object key)`
Gets the object associated with the specified key in the hashtable.
`Object[]`
`getCachedObjects()`
Return an array with all objects currently contained in the cache.
`Map<String,Object>`
`getStatistics()`
Returns a map of statistics about the cache
`void`
`init(Application app)`
Set the `Application` instance for the cache.
`boolean`
`isEmpty()`
`Object`
`put(Object key, Object value)`
Puts the specified element into the hashtable, using the specified key.
`Object`
`remove(Object key)`
Removes the element corresponding to the key.
`void`
`setCapacity(int capacity)`
`void`
`shutdown()`
Called when the application holding the cache is stopped.
`int`
`size()`
Return the number of objects currently stored in the cache.
`String`
`toString()`
`void`
`updateProperties(Properties props)`
Called when the application's properties have been updated to let the cache implementation update its settings.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### CacheMap

public CacheMap()
Zero argument constructor. Creates a CacheMap with capacity of 1000 and load factor 0.75

### CacheMap

public CacheMap(int initialCapacity, float loadFactor)

### CacheMap

public CacheMap(int initialCapacity)

## Method Details

### size

public int size()
Description copied from interface: `ObjectCache`
Return the number of objects currently stored in the cache.

Specified by:
  `size` in interface `ObjectCache`
Returns:
  the number of cached items

### isEmpty

public boolean isEmpty()

### setCapacity

public void setCapacity(int capacity)

### containsValue

public boolean containsValue(Object value)

### containsKey

public boolean containsKey(Object key)
Description copied from interface: `ObjectCache`
Returns true if the collection contains an element for the key.

Specified by:
  `containsKey` in interface `ObjectCache`
Parameters:
  `key` - the key that we are looking for

### containsKeys

public int containsKeys(Object[] keys)
Description copied from interface: `ObjectCache`
Returns the number of keys in object array `keys` that were not found in the Map. Those keys that are contained in the Map are nulled out in the array.

Specified by:
  `containsKeys` in interface `ObjectCache`
Parameters:
  `keys` - an array of key objects we are looking for
See Also:
  - `ObjectCache.containsKey(java.lang.Object)`

### get

public Object get(Object key)
Description copied from interface: `ObjectCache`
Gets the object associated with the specified key in the hashtable.

Specified by:
  `get` in interface `ObjectCache`
Parameters:
  `key` - the specified key
Returns:
  the element for the key or null if the key is not defined in the hash table.
See Also:
  - `ObjectCache.put(java.lang.Object, java.lang.Object)`

### put

public Object put(Object key, Object value)
Description copied from interface: `ObjectCache`
Puts the specified element into the hashtable, using the specified key. The element may be retrieved by doing a get() with the same key. The key and the element cannot be null.

Specified by:
  `put` in interface `ObjectCache`
Parameters:
  `key` - the specified key in the hashtable
  `value` - the specified element
Returns:
  the old value of the key, or null if it did not have one.
See Also:
  - `ObjectCache.get(java.lang.Object)`

### remove

public Object remove(Object key)
Description copied from interface: `ObjectCache`
Removes the element corresponding to the key. Does nothing if the key is not present.

Specified by:
  `remove` in interface `ObjectCache`
Parameters:
  `key` - the key that needs to be removed
Returns:
  the value of key, or null if the key was not found.

### clear

public boolean clear()
Description copied from interface: `ObjectCache`
Removes all items currently stored in the cache.

Specified by:
  `clear` in interface `ObjectCache`
Returns:
  true if the operation succeeded

### shutdown

public void shutdown()
Description copied from interface: `ObjectCache`
Called when the application holding the cache is stopped.

Specified by:
  `shutdown` in interface `ObjectCache`

### init

public void init(Application app)
Description copied from interface: `ObjectCache`
Set the `Application` instance for the cache.

Specified by:
  `init` in interface `ObjectCache`
Parameters:
  `app` - the app instance

### updateProperties

public void updateProperties(Properties props)
Description copied from interface: `ObjectCache`
Called when the application's properties have been updated to let the cache implementation update its settings.

Specified by:
  `updateProperties` in interface `ObjectCache`

### getCachedObjects

public Object[] getCachedObjects()
Description copied from interface: `ObjectCache`
Return an array with all objects currently contained in the cache.

Specified by:
  `getCachedObjects` in interface `ObjectCache`

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### createTable

protected Map createTable(int capacity, float loadFactor)
Override this method to use custom Map implementations. The default implementation returns a java.util.HashMap instance.

Parameters:
  `capacity` - the initial capacity
  `loadFactor` - the load factor
Returns:
  a new Map used for internal caching

### getStatistics

public Map<String,Object> getStatistics()
Description copied from interface: `ObjectCache`
Returns a map of statistics about the cache

Specified by:
  `getStatistics` in interface `ObjectCache`