Package helma.util
Class CacheMap
java.lang.Object
helma.util.CacheMap
- All Implemented Interfaces:
ObjectCache
- Direct Known Subclasses:
WeakCacheMap
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
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 arraykeys
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.Gets the object associated with the specified key in the hashtable.Object[]
Return an array with all objects currently contained in the cache.Returns a map of statistics about the cachevoid
init
(Application app) Set theApplication
instance for the cache.boolean
isEmpty()
Puts the specified element into the hashtable, using the specified 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.toString()
void
updateProperties
(Properties props) Called when the application's properties have been updated to let the cache implementation update its settings.
-
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 interfaceObjectCache
- Returns:
- the number of cached items
-
isEmpty
public boolean isEmpty() -
setCapacity
public void setCapacity(int capacity) -
containsValue
-
containsKey
Description copied from interface:ObjectCache
Returns true if the collection contains an element for the key.- Specified by:
containsKey
in interfaceObjectCache
- Parameters:
key
- the key that we are looking for
-
containsKeys
Description copied from interface:ObjectCache
Returns the number of keys in object arraykeys
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 interfaceObjectCache
- Parameters:
keys
- an array of key objects we are looking for- See Also:
-
get
Description copied from interface:ObjectCache
Gets the object associated with the specified key in the hashtable.- Specified by:
get
in interfaceObjectCache
- 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:
-
put
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 interfaceObjectCache
- Parameters:
key
- the specified key in the hashtablevalue
- the specified element- Returns:
- the old value of the key, or null if it did not have one.
- See Also:
-
remove
Description copied from interface:ObjectCache
Removes the element corresponding to the key. Does nothing if the key is not present.- Specified by:
remove
in interfaceObjectCache
- 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 interfaceObjectCache
- 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 interfaceObjectCache
-
init
Description copied from interface:ObjectCache
Set theApplication
instance for the cache.- Specified by:
init
in interfaceObjectCache
- Parameters:
app
- the app instance
-
updateProperties
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 interfaceObjectCache
- Parameters:
props
-
-
getCachedObjects
Description copied from interface:ObjectCache
Return an array with all objects currently contained in the cache.- Specified by:
getCachedObjects
in interfaceObjectCache
-
toString
-
createTable
Override this method to use custom Map implementations. The default implementation returns a java.util.HashMap instance.- Parameters:
capacity
- the initial capacityloadFactor
- the load factor- Returns:
- a new Map used for internal caching
-
getStatistics
Description copied from interface:ObjectCache
Returns a map of statistics about the cache- Specified by:
getStatistics
in interfaceObjectCache
-