Package helma.util
Class CacheMap
- java.lang.Object
-
- helma.util.CacheMap
-
- All Implemented Interfaces:
ObjectCache
- Direct Known Subclasses:
WeakCacheMap
public class CacheMap extends java.lang.Object implements ObjectCache
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
clear()
Removes all items currently stored in the cache.boolean
containsKey(java.lang.Object key)
Returns true if the collection contains an element for the key.int
containsKeys(java.lang.Object[] keys)
Returns the number of keys in object arraykeys
that were not found in the Map.boolean
containsValue(java.lang.Object value)
protected java.util.Map
createTable(int capacity, float loadFactor)
Override this method to use custom Map implementations.java.lang.Object
get(java.lang.Object key)
Gets the object associated with the specified key in the hashtable.java.lang.Object[]
getCachedObjects()
Return an array with all objects currently contained in the cache.java.util.Map<java.lang.String,java.lang.Object>
getStatistics()
Returns a map of statistics about the cachevoid
init(Application app)
Set theApplication
instance for the cache.boolean
isEmpty()
java.lang.Object
put(java.lang.Object key, java.lang.Object value)
Puts the specified element into the hashtable, using the specified key.java.lang.Object
remove(java.lang.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.java.lang.String
toString()
void
updateProperties(java.util.Properties props)
Called when the application's properties have been updated to let the cache implementation update its settings.
-
-
-
Method Detail
-
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
public boolean containsValue(java.lang.Object value)
-
containsKey
public boolean containsKey(java.lang.Object key)
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
public int containsKeys(java.lang.Object[] keys)
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:
ObjectCache.containsKey(java.lang.Object)
-
get
public java.lang.Object get(java.lang.Object key)
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:
ObjectCache.put(java.lang.Object, java.lang.Object)
-
put
public java.lang.Object put(java.lang.Object key, java.lang.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 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:
ObjectCache.get(java.lang.Object)
-
remove
public java.lang.Object remove(java.lang.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 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
public void init(Application app)
Description copied from interface:ObjectCache
Set theApplication
instance for the cache.- Specified by:
init
in interfaceObjectCache
- Parameters:
app
- the app instance
-
updateProperties
public void updateProperties(java.util.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 interfaceObjectCache
-
getCachedObjects
public java.lang.Object[] getCachedObjects()
Description copied from interface:ObjectCache
Return an array with all objects currently contained in the cache.- Specified by:
getCachedObjects
in interfaceObjectCache
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
createTable
protected java.util.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 capacityloadFactor
- the load factor- Returns:
- a new Map used for internal caching
-
getStatistics
public java.util.Map<java.lang.String,java.lang.Object> getStatistics()
Description copied from interface:ObjectCache
Returns a map of statistics about the cache- Specified by:
getStatistics
in interfaceObjectCache
-
-