Module org.eclipse.persistence.core
Class HardCacheWeakIdentityMap
java.lang.Object
org.eclipse.persistence.internal.identitymaps.AbstractIdentityMap
org.eclipse.persistence.internal.identitymaps.FullIdentityMap
org.eclipse.persistence.internal.identitymaps.WeakIdentityMap
org.eclipse.persistence.internal.identitymaps.HardCacheWeakIdentityMap
- All Implemented Interfaces:
Serializable
,Cloneable
,IdentityMap
- Direct Known Subclasses:
SoftCacheWeakIdentityMap
Purpose: A HardCacheWeakIdentityMap is identical to the weak identity map, however the weak reference
can be a performance problem for some types of apps because it can cause too much garbage collection
of objects read causing them to be re-read and re-built (this defeats the purpose of the cache).
The hard weak cache solves this by also holding a fixed number of objects in memory to improve caching.
This class makes use of an exposed node linked list to maintain the objects by storing the link nodes in the cache key.
Responsibilities:
- Guarantees identity
- Allows garbage collection
- Increases performance by maintaining a fixed size cache of LRU objects when memory is available
- The default size of the reference cache is half the max size
- Since:
- TOPLink/Java 1.2
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
Inner class to define the specialized weak cache key. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ExposedNodeLinkedList
A subset of cache entries have hard references maintained in this list to reduce garbage collection frequencyFields inherited from class org.eclipse.persistence.internal.identitymaps.WeakIdentityMap
cleanupCount, cleanupSize
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
ConstructorsConstructorDescriptionHardCacheWeakIdentityMap
(int size, ClassDescriptor descriptor, AbstractSession session, boolean isIsolated) -
Method Summary
Modifier and TypeMethodDescriptionbuildReference
(Object object) Allows subclass to create a SoftReference to the object.createCacheKey
(Object primaryKey, Object object, Object writeLockValue, long readTime) Use a ReferenceCacheKey that also stores the linked list node to manage the LRU sub-cache of references.Return the linked reference cache.boolean
hasReference
(Object reference) Checks if the object is null, or reference's object is null.Store the object in the cache at its primary key, and add to sub-cache list.Remove the cache key from the map and the sub-cache list.void
updateMaxSize
(int maxSize) This method will be used to update the max cache size.Methods inherited from class org.eclipse.persistence.internal.identitymaps.WeakIdentityMap
checkCleanup, cleanupDeadCacheKeys, putCacheKeyIfAbsent
Methods inherited from class org.eclipse.persistence.internal.identitymaps.FullIdentityMap
clone, cloneKeys, collectLocks, elements, getCacheKey, getCacheKeys, getSize, getSize, keys, keys, lazyRelationshipLoaded, 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
-
referenceCache
A subset of cache entries have hard references maintained in this list to reduce garbage collection frequency
-
-
Constructor Details
-
HardCacheWeakIdentityMap
public HardCacheWeakIdentityMap(int size, ClassDescriptor descriptor, AbstractSession session, boolean isIsolated)
-
-
Method Details
-
createCacheKey
public CacheKey createCacheKey(Object primaryKey, Object object, Object writeLockValue, long readTime) Use a ReferenceCacheKey that also stores the linked list node to manage the LRU sub-cache of references.- Overrides:
createCacheKey
in classWeakIdentityMap
-
getReferenceCache
Return the linked reference cache. -
buildReference
Allows subclass to create a SoftReference to the object.- Parameters:
object
- is the domain object to cache.
-
hasReference
Checks if the object is null, or reference's object is null.- Parameters:
reference
- the object for hard or the reference for soft.
-
remove
Remove the cache key from the map and the sub-cache list.- Specified by:
remove
in interfaceIdentityMap
- Overrides:
remove
in classFullIdentityMap
- Returns:
- the object held within the CacheKey or null if no object cached for given cacheKey.
-
put
Store the object in the cache at its primary key, and add to sub-cache list.- Specified by:
put
in interfaceIdentityMap
- Overrides:
put
in classFullIdentityMap
- Parameters:
primaryKey
- is the primary key for the object.object
- is the domain object to cache.writeLockValue
- is the current write lock value of object, if null the version is ignored.
-
updateMaxSize
public void updateMaxSize(int maxSize) This method will be used to update the max cache size.- Specified by:
updateMaxSize
in interfaceIdentityMap
- Overrides:
updateMaxSize
in classAbstractIdentityMap
-