Package net.sourceforge.jtds.jdbc.cache
Class ProcedureCache
- java.lang.Object
-
- net.sourceforge.jtds.jdbc.cache.ProcedureCache
-
- All Implemented Interfaces:
StatementCache
public class ProcedureCache extends java.lang.Object implements StatementCache
LRU cache for procedures and statement handles.- Version:
- $Id: ProcedureCache.java,v 1.5 2005-07-05 16:44:25 alin_sinpalean Exp $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classProcedureCache.CacheEntryEncapsulates the cached Object and implements the linked list used to implement the LRU logic.
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashMapcacheThe actual cache instance.(package private) intcacheSizeMaximum cache size or 0 to disable.(package private) java.util.ArrayListfreeList of redundant cache entries.(package private) ProcedureCache.CacheEntryheadHead node of the linked list.private static intMAX_INITIAL_SIZEThe maximum initial HashMap size.(package private) ProcedureCache.CacheEntrytailTail node of the linked list.
-
Constructor Summary
Constructors Constructor Description ProcedureCache(int cacheSize)Constructs a new statement cache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectget(java.lang.String key)Retrieves a ProcEntry object from the cache.java.util.CollectiongetObsoleteHandles(java.util.Collection handles)Obtains a list of statement handles or procedures that can now be dropped.voidput(java.lang.String key, java.lang.Object handle)Inserts a new entry, identified by a key, into the cache.voidremove(java.lang.String key)Removes a redundant entry from the cache.private voidscavengeCache()Removes unused entries trying to bring down the cache to the requested size.
-
-
-
Field Detail
-
MAX_INITIAL_SIZE
private static final int MAX_INITIAL_SIZE
The maximum initial HashMap size.- See Also:
- Constant Field Values
-
cache
private java.util.HashMap cache
The actual cache instance.
-
cacheSize
int cacheSize
Maximum cache size or 0 to disable.
-
head
ProcedureCache.CacheEntry head
Head node of the linked list.
-
tail
ProcedureCache.CacheEntry tail
Tail node of the linked list.
-
free
java.util.ArrayList free
List of redundant cache entries.
-
-
Method Detail
-
get
public java.lang.Object get(java.lang.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.- Specified by:
getin interfaceStatementCache- Parameters:
key- the key value identifying the required entry- Returns:
- the keyed entry as an
Objector null if the entry does not exist
-
put
public void put(java.lang.String key, java.lang.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.- Specified by:
putin interfaceStatementCache- Parameters:
key- value used to identify the entryhandle- proc entry to be inserted into the cache
-
remove
public void remove(java.lang.String key)
Removes a redundant entry from the cache.- Specified by:
removein interfaceStatementCache- Parameters:
key- value that identifies the cache entry
-
getObsoleteHandles
public java.util.Collection getObsoleteHandles(java.util.Collection handles)
Obtains a list of statement handles or procedures that can now be dropped.- Specified by:
getObsoleteHandlesin interfaceStatementCache- Parameters:
handles- a collection of single use statements that will be returned for dropping if the cache is disabled- Returns:
- the collection of redundant statments for dropping
-
scavengeCache
private void scavengeCache()
-
-