public class CacheIdentityMap extends FullIdentityMap
Purpose: A fixed size LRU cache
Using a linked list as well as the hashtable from the superclass a LRU cache is maintained. When a get is executed the LRU list is updated and when a new object is inserted the object at the start of the list is deleted (provided the maxSize has been reached).
Responsibilities:
| Modifier and Type | Field and Description |
|---|---|
protected LinkedCacheKey |
first
Provide handles on the linked list
|
protected LinkedCacheKey |
last
Provide handles on the linked list
|
cacheKeysmaxSize, searchKey| Constructor and Description |
|---|
CacheIdentityMap(int size)
Initialize newly instantiated CacheIdentityMap.
|
| Modifier and Type | Method and Description |
|---|---|
CacheKey |
createCacheKey(java.util.Vector primaryKey,
java.lang.Object object,
java.lang.Object writeLockValue,
long readTime) |
protected void |
ensureFixedSize()
Reduces the size of the receiver down to the maxSize removing objects from the
start of the linked list.
|
protected CacheKey |
getCacheKey(java.util.Vector primaryKeys)
Access the object within the table for the given primaryKey.
|
protected LinkedCacheKey |
insertLink(LinkedCacheKey key)
Insert a new element into the linked list of LinkedCacheKeys.
|
protected void |
put(CacheKey cacheKey)
Store the object in the identity map with the linked cache key
|
java.lang.Object |
remove(CacheKey key)
Remove the LinkedCacheKey from the cache as well as from the linked list.
|
protected LinkedCacheKey |
removeLink(LinkedCacheKey key)
Remove the LinkedCacheKey from the linked list.
|
void |
updateMaxSize(int maxSize)
INTERNAL:
This method will be used to update the max cache size, any objects exceeding the max cache size will
be remove from the cache.
|
clone, collectLocks, elements, getCacheKey, getCacheKeys, getSize, getSize, keys, put, resetCacheKey, resetCacheKey, setCacheKeysacquireDeferredLock, acquireLock, acquireLockNoWait, acquireReadLockOnCacheKey, acquireReadLockOnCacheKeyNoWait, containsKey, createCacheKey, get, getCacheKeyWithReadLock, getDefaultIdentityMapClass, getMaxSize, getSearchKey, getWrapper, getWriteLockValue, initialize, remove, setMaxSize, setSearchKey, setWrapper, setWriteLockValue, toString, updateCacheKeyprotected LinkedCacheKey first
protected LinkedCacheKey last
public CacheIdentityMap(int size)
size - int The size of the Cachepublic CacheKey createCacheKey(java.util.Vector primaryKey, java.lang.Object object, java.lang.Object writeLockValue, long readTime)
createCacheKey in class IdentityMapprotected void ensureFixedSize()
protected CacheKey getCacheKey(java.util.Vector primaryKeys)
getCacheKey in class IdentityMapaVector - is the primary key for the object to search for.protected LinkedCacheKey insertLink(LinkedCacheKey key)
protected void put(CacheKey cacheKey)
put in class FullIdentityMappublic java.lang.Object remove(CacheKey key)
remove in class FullIdentityMapprotected LinkedCacheKey removeLink(LinkedCacheKey key)
public void updateMaxSize(int maxSize)
updateMaxSize in class IdentityMap