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
public class HardCacheWeakIdentityMap extends WeakIdentityMap
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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
HardCacheWeakIdentityMap.ReferenceCacheKey
Inner class to define the specialized weak cache key.
-
Field Summary
Fields Modifier and Type Field Description protected ExposedNodeLinkedList
referenceCache
A subset of cache entries have hard references maintained in this list to reduce garbage collection frequency-
Fields 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
Constructors Constructor Description HardCacheWeakIdentityMap(int size, ClassDescriptor descriptor, AbstractSession session, boolean isIsolated)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
buildReference(Object object)
Allows subclass to create a SoftReference to the object.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.ExposedNodeLinkedList
getReferenceCache()
Return the linked reference cache.boolean
hasReference(Object reference)
Checks if the object is null, or reference's object is null.CacheKey
put(Object primaryKey, Object object, Object writeLockValue, long readTime)
Store the object in the cache at its primary key, and add to sub-cache list.Object
remove(CacheKey cacheKey)
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 Detail
-
referenceCache
protected ExposedNodeLinkedList referenceCache
A subset of cache entries have hard references maintained in this list to reduce garbage collection frequency
-
-
Constructor Detail
-
HardCacheWeakIdentityMap
public HardCacheWeakIdentityMap(int size, ClassDescriptor descriptor, AbstractSession session, boolean isIsolated)
-
-
Method Detail
-
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
public ExposedNodeLinkedList getReferenceCache()
Return the linked reference cache.
-
buildReference
public Object buildReference(Object object)
Allows subclass to create a SoftReference to the object.- Parameters:
object
- is the domain object to cache.
-
hasReference
public boolean hasReference(Object reference)
Checks if the object is null, or reference's object is null.- Parameters:
reference
- the object for hard or the reference for soft.
-
remove
public Object remove(CacheKey cacheKey)
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
public CacheKey put(Object primaryKey, Object object, Object writeLockValue, long readTime)
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
-
-