FileDocCategorySizeDatePackage
Cache.javaAPI DocGlassfish v2 API8706Fri May 04 22:35:28 BST 2007com.sun.appserv.util.cache

Cache

public interface Cache
Cache Generic cache interface

Fields Summary
Constructors Summary
Methods Summary
public voidadd(java.lang.Object key, java.lang.Object value)
add the given value to the cache at the specified key

param
key lookup key
param
object item value to be stored This function is suitable for multi-valued keys.

public voidadd(java.lang.Object key, java.lang.Object value, int size)
add the given value with specified size to the cache at specified key

param
key lookup key
param
object item value to be stored
param
size in bytes of the value being added This function is suitable for multi-valued keys.

public voidaddCacheListener(CacheListener listener)
add the cache module listener

param
listener CacheListener implementation

public intclear()
clear all the entries from the cache.

returns
the number of entries cleared from the cache

public voidclearStats()
clear all stats

public booleancontains(java.lang.Object key)
check if the cache contains the item at the key

param
key lookup key
returns
true if there is an item stored at the key; false if not.

public voiddestroy()
Destroys this cache. This method should perform final clean ups.

public java.util.Enumerationelements()
get an Enumeration for the keys stored in the cache

returns
an Enumeration XXX: should use Iterator which is based on Collections

public java.lang.Objectget(java.lang.Object key)
get the item stored at the key.

param
key lookup key
returns
the item stored at the key; null if not found. This function returns first value, for a multi-valued key.

public java.util.IteratorgetAll(java.lang.Object key)
get all the items with the given key.

param
key lookup key
returns
an Iterator over the items with the given key

public intgetEntryCount()
get the number of entries in the cache

return
the number of entries the cache currently holds

public intgetIndex(java.lang.Object key)
get the index of the item given a key

param
key of the entry
return
the index to be used in the cache

public java.lang.ObjectgetStatByName(java.lang.String key)
get the desired statistic counter

param
key to corresponding stat
return
an Object corresponding to the stat See also: Constant.java for the key

public java.util.MapgetStats()
get the stats snapshot

return
a Map of stats See also: Constant.java for the keys

public voidinit(int maxEntries, float loadFactor, java.util.Properties props)
initialize the cache

param
maxEntries maximum number of entries expected in the cache
param
loadFactor the load factor
param
props opaque list of properties for a given cache implementation
throws
a generic Exception if the initialization failed

public voidinit(int maxEntries, java.util.Properties props)
initialize the cache with the default load factor (0.75)

param
maxEntries maximum number of entries expected in the cache
param
props opaque list of properties for a given cache implementation
throws
a generic Exception if the initialization failed

public booleanisEmpty()
is this cache empty?

returns
true if the cache is empty; false otherwise.

public java.util.Iteratorkeys()
get an Iterator for the keys stored in the cache

returns
an Iterator

public voidnotifyRefresh(int index)
notify threads waiting for a refresh on the object associated with the key

param
index index of the entry. The index must be obtained via one of the getIndex() methods.

public java.lang.Objectput(java.lang.Object key, java.lang.Object value)
cache the given value at the specified key and return previous value

param
key lookup key
param
object item value to be stored
returns
the previous item stored at the key; null if not found. This function replaces first value, for a multi-valued key.

public java.lang.Objectput(java.lang.Object key, java.lang.Object value, int size)
cache the given value at the specified key and return previous value

param
key lookup key
param
object item value to be stored
param
size in bytes of the value being cached
returns
the previous item stored at the key; null if not found. This function replaces first value, for a multi-valued key.

public java.lang.Objectremove(java.lang.Object key)
remove the item with the given key.

param
key lookup key
returns
the item stored at the key; null if not found. This function removes first value, for a multi-valued key.

public java.lang.Objectremove(java.lang.Object key, java.lang.Object value)
remove the given value stored at the key.

param
key lookup key
param
value to match (for multi-valued keys)
returns
the item stored at the key; null if not found.

public voidremoveAll(java.lang.Object key)
remove all the item with the given key.

param
key lookup key

public voidtrimExpiredEntries(int maxCount)
trim the expired entries from the cache.

param
maxCount maximum number of invalid entries to trim specify Integer.MAX_VALUE to trim all timedout entries This call is to be scheduled by a thread managed by the container.

public java.util.Iteratorvalues()
get an Iterator for the values stored in the cache

returns
an Iterator

public booleanwaitRefresh(int index)
wait for a refresh on the object associated with the key

param
index index of the entry. The index must be obtained via one of the getIndex() methods.
returns
true on successful notification, or false if there is no thread refreshing this entry.