net.sourceforge.jtds.jdbc.cache
Class ProcedureCache
java.lang.Object
net.sourceforge.jtds.jdbc.cache.ProcedureCache
- StatementCache
public class ProcedureCache
extends java.lang.Object
LRU cache for procedures and statement handles.
$Id: ProcedureCache.java,v 1.5 2005/07/05 16:44:25 alin_sinpalean Exp $private static class | ProcedureCache.CacheEntry - Encapsulates the cached Object and implements the linked list used to
implement the LRU logic.
|
Object | get(String key) - Retrieves a ProcEntry object from the cache.
|
Collection | getObsoleteHandles(Collection handles) - Obtains a list of statement handles or procedures that can now be
dropped.
|
void | put(String key, Object handle) - Inserts a new entry, identified by a key, into the cache.
|
void | remove(String key) - Removes a redundant entry from the cache.
|
private void | scavengeCache() - Removes unused entries trying to bring down the cache to the requested
size.
|
MAX_INITIAL_SIZE
private static final int MAX_INITIAL_SIZE
The maximum initial HashMap size.
cache
private HashMap cache
The actual cache instance.
cacheSize
(package private) int cacheSize
Maximum cache size or 0 to disable.
free
(package private) ArrayList free
List of redundant cache entries.
ProcedureCache
public ProcedureCache(int cacheSize)
Constructs a new statement cache.
cacheSize
- maximum cache size or 0 to disable caching
get
public Object get(String key)
Retrieves a ProcEntry object from the cache.
If the entry exists it is moved to the front of the linked list to keep
it alive as long as possible.
- get in interface StatementCache
key
- the key value identifying the required entry
- the keyed entry as an
Object
or null if the entry
does not exist
getObsoleteHandles
public Collection getObsoleteHandles(Collection handles)
Obtains a list of statement handles or procedures that can now be
dropped.
- getObsoleteHandles in interface StatementCache
handles
- a collection of single use statements that will be
returned for dropping if the cache is disabled
- the collection of redundant statments for dropping
put
public void put(String key,
Object handle)
Inserts a new entry, identified by a key, into the cache.
If the cache is full then one or more entries are removed and
transferred to a list for later destruction.
- put in interface StatementCache
key
- value used to identify the entryhandle
- proc entry to be inserted into the cache
remove
public void remove(String key)
Removes a redundant entry from the cache.
- remove in interface StatementCache
key
- value that identifies the cache entry
scavengeCache
private void scavengeCache()
Removes unused entries trying to bring down the cache to the requested
size. The removed entries are placed in the
free
list.
Note: entries that are in use will not be removed so it is
possible for the cache to still be larger than
cacheSize
after
the call finishes.
Generated on June 12 2008