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
|
cacheKeys
maxSize, searchKey
Constructor and Description |
---|
CacheIdentityMap(int size)
Initialize newly instantiated CacheIdentityMap.
|
Modifier and Type | Method and Description |
---|---|
CacheKey |
createCacheKey(Vector primaryKey,
Object object,
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(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
|
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, setCacheKeys
acquireDeferredLock, acquireLock, acquireLockNoWait, acquireReadLockOnCacheKey, acquireReadLockOnCacheKeyNoWait, containsKey, createCacheKey, get, getCacheKeyWithReadLock, getDefaultIdentityMapClass, getMaxSize, getSearchKey, getWrapper, getWriteLockValue, initialize, remove, setMaxSize, setSearchKey, setWrapper, setWriteLockValue, toString, updateCacheKey
protected LinkedCacheKey first
protected LinkedCacheKey last
public CacheIdentityMap(int size)
size
- int The size of the Cachepublic CacheKey createCacheKey(Vector primaryKey, Object object, Object writeLockValue, long readTime)
createCacheKey
in class IdentityMap
protected void ensureFixedSize()
protected CacheKey getCacheKey(Vector primaryKeys)
getCacheKey
in class IdentityMap
aVector
- is the primary key for the object to search for.protected LinkedCacheKey insertLink(LinkedCacheKey key)
protected void put(CacheKey cacheKey)
put
in class FullIdentityMap
public Object remove(CacheKey key)
remove
in class FullIdentityMap
protected LinkedCacheKey removeLink(LinkedCacheKey key)
public void updateMaxSize(int maxSize)
updateMaxSize
in class IdentityMap
Copyright © 2021. All rights reserved.