Package net.sourceforge.jtds.jdbc.cache
Class ProcedureCache
java.lang.Object
net.sourceforge.jtds.jdbc.cache.ProcedureCache
- All Implemented Interfaces:
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 ClassesModifier and TypeClassDescriptionprivate static class
Encapsulates the cached Object and implements the linked list used to implement the LRU logic. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate HashMap
The actual cache instance.(package private) int
Maximum cache size or 0 to disable.(package private) ArrayList
List of redundant cache entries.(package private) ProcedureCache.CacheEntry
Head node of the linked list.private static final int
The maximum initial HashMap size.(package private) ProcedureCache.CacheEntry
Tail node of the linked list. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionRetrieves a ProcEntry object from the cache.getObsoleteHandles
(Collection handles) Obtains a list of statement handles or procedures that can now be dropped.void
Inserts a new entry, identified by a key, into the cache.void
Removes a redundant entry from the cache.private void
Removes unused entries trying to bring down the cache to the requested size.
-
Field Details
-
MAX_INITIAL_SIZE
private static final int MAX_INITIAL_SIZEThe maximum initial HashMap size.- See Also:
-
cache
The actual cache instance. -
cacheSize
int cacheSizeMaximum cache size or 0 to disable. -
head
Head node of the linked list. -
tail
Tail node of the linked list. -
free
ArrayList freeList of redundant cache entries.
-
-
Constructor Details
-
ProcedureCache
public ProcedureCache(int cacheSize) Constructs a new statement cache.- Parameters:
cacheSize
- maximum cache size or 0 to disable caching
-
-
Method Details
-
get
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:
get
in interfaceStatementCache
- Parameters:
key
- the key value identifying the required entry- Returns:
- the keyed entry as an
Object
or null if the entry does not exist
-
put
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:
put
in interfaceStatementCache
- Parameters:
key
- value used to identify the entryhandle
- proc entry to be inserted into the cache
-
remove
Removes a redundant entry from the cache.- Specified by:
remove
in interfaceStatementCache
- Parameters:
key
- value that identifies the cache entry
-
getObsoleteHandles
Obtains a list of statement handles or procedures that can now be dropped.- Specified by:
getObsoleteHandles
in 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()
-