Module org.eclipse.persistence.core
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
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:
-
Field Summary
Modifier and TypeFieldDescriptionprotected LinkedCacheKey
Provide handles on the linked listprotected LinkedCacheKey
Provide handles on the linked listFields 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
ConstructorDescriptionCacheIdentityMap
(int size, ClassDescriptor descriptor, AbstractSession session, boolean isolated) -
Method Summary
Modifier and TypeMethodDescriptioncreateCacheKey
(Object primaryKey, Object object, Object writeLockValue, long readTime) Create the correct type of CacheKey for this map.protected void
Reduces the size of the receiver down to the maxSize removing objects from the start of the linked list.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.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 Details
-
first
Provide handles on the linked list -
last
Provide handles on the linked list
-
-
Constructor Details
-
CacheIdentityMap
public CacheIdentityMap(int size, ClassDescriptor descriptor, AbstractSession session, boolean isolated)
-
-
Method Details
-
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
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
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
Also insert the link if the cacheKey is put.- Overrides:
putCacheKeyIfAbsent
in classFullIdentityMap
-
remove
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
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
-