Class CacheIdentityMap
- java.lang.Object
-
- org.eclipse.persistence.internal.identitymaps.AbstractIdentityMap
-
- org.eclipse.persistence.internal.identitymaps.FullIdentityMap
-
- org.eclipse.persistence.internal.identitymaps.CacheIdentityMap
-
- All Implemented Interfaces:
Serializable
,Cloneable
,IdentityMap
public class CacheIdentityMap extends FullIdentityMap
Purpose: A fixed size LRU cache
Using a linked list as well as the map 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:
- Guarantees identity through primary key values
- Keeps the LRU linked list updated.
- Since:
- TOPLink/Java 1.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected LinkedCacheKey
first
Provide handles on the linked listprotected LinkedCacheKey
last
Provide handles on the linked list-
Fields inherited from class org.eclipse.persistence.internal.identitymaps.FullIdentityMap
cacheKeys
-
Fields inherited from class org.eclipse.persistence.internal.identitymaps.AbstractIdentityMap
descriptor, isIsolated, maxSize, session
-
-
Constructor Summary
Constructors Constructor Description CacheIdentityMap(int size, ClassDescriptor descriptor, AbstractSession session, boolean isolated)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CacheKey
createCacheKey(Object primaryKey, Object object, Object writeLockValue, long readTime)
Create the correct type of CacheKey for this map.protected void
ensureFixedSize()
Reduces the size of the receiver down to the maxSize removing objects from the start of the linked list.CacheKey
getCacheKey(Object primaryKeys, boolean forMerge)
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 CacheKey
putCacheKeyIfAbsent(CacheKey searchKey)
Also insert the link if the cacheKey is put.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.-
Methods inherited from class org.eclipse.persistence.internal.identitymaps.FullIdentityMap
clone, cloneKeys, collectLocks, elements, getCacheKeys, getSize, getSize, keys, keys, lazyRelationshipLoaded, put, resetCacheKey, setCacheKeys
-
Methods inherited from class org.eclipse.persistence.internal.identitymaps.AbstractIdentityMap
acquireDeferredLock, acquireLock, acquireLockNoWait, acquireLockWithWait, acquireReadLockOnCacheKey, acquireReadLockOnCacheKeyNoWait, containsKey, get, getAllCacheKeysFromIdentityMapWithEntityPK, getAllFromIdentityMapWithEntityPK, getCacheKeyForLock, getCacheKeyWithReadLock, getDefaultIdentityMapClass, getDescriptor, getDescriptorClass, getMaxSize, getWrapper, getWriteLockValue, release, remove, setDescriptor, setMaxSize, setWrapper, setWriteLockValue, toString
-
-
-
-
Field Detail
-
first
protected LinkedCacheKey first
Provide handles on the linked list
-
last
protected LinkedCacheKey last
Provide handles on the linked list
-
-
Constructor Detail
-
CacheIdentityMap
public CacheIdentityMap(int size, ClassDescriptor descriptor, AbstractSession session, boolean isolated)
-
-
Method Detail
-
createCacheKey
public CacheKey createCacheKey(Object primaryKey, Object object, Object writeLockValue, long readTime)
Description copied from class:AbstractIdentityMap
Create the correct type of CacheKey for this map.- Overrides:
createCacheKey
in classAbstractIdentityMap
-
ensureFixedSize
protected void ensureFixedSize()
Reduces the size of the receiver down to the maxSize removing objects from the start of the linked list.
-
getCacheKey
public CacheKey getCacheKey(Object primaryKeys, boolean forMerge)
Access the object within the table for the given primaryKey. Move the accessed key to the top of the order keys linked list to maintain LRU.- Specified by:
getCacheKey
in interfaceIdentityMap
- Overrides:
getCacheKey
in classFullIdentityMap
- Parameters:
primaryKeys
- is the primary key for the object to search for.- Returns:
- the LinkedCacheKey or null if none found for primaryKey
-
insertLink
protected LinkedCacheKey insertLink(LinkedCacheKey key)
Insert a new element into the linked list of LinkedCacheKeys. New elements (Recently Used) are added at the end (last). Callers of this method must synchronize on the start of the list (this.first).- Returns:
- the added LinkedCacheKey
-
putCacheKeyIfAbsent
protected CacheKey putCacheKeyIfAbsent(CacheKey searchKey)
Also insert the link if the cacheKey is put.- Overrides:
putCacheKeyIfAbsent
in classFullIdentityMap
-
remove
public Object remove(CacheKey key)
Remove the LinkedCacheKey from the cache as well as from the linked list.- Specified by:
remove
in interfaceIdentityMap
- Overrides:
remove
in classFullIdentityMap
- Returns:
- the LinkedCacheKey to be removed.
-
removeLink
protected LinkedCacheKey removeLink(LinkedCacheKey key)
Remove the LinkedCacheKey from the linked list. Callers of this method must synchronize on the start of the list (this.first).- Returns:
- the removed LinkedCacheKey.
-
updateMaxSize
public 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. Please note that this does not remove the object from the identityMap, except in the case of the CacheIdentityMap.- Specified by:
updateMaxSize
in interfaceIdentityMap
- Overrides:
updateMaxSize
in classAbstractIdentityMap
-
-