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 classEncapsulates the cached Object and implements the linked list used to implement the LRU logic. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate HashMapThe actual cache instance.(package private) intMaximum cache size or 0 to disable.(package private) ArrayListList of redundant cache entries.(package private) ProcedureCache.CacheEntryHead node of the linked list.private static final intThe maximum initial HashMap size.(package private) ProcedureCache.CacheEntryTail 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.voidInserts a new entry, identified by a key, into the cache.voidRemoves a redundant entry from the cache.private voidRemoves 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:
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
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
Removes a redundant entry from the cache.- Specified by:
removein 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:
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()
-