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:
Modifier and Type | Class and Description |
---|---|
class |
HardCacheWeakIdentityMap.ReferenceCacheKey
Inner class to define the specialized weak cache key.
|
Constructor and Description |
---|
HardCacheWeakIdentityMap(int size,
ClassDescriptor descriptor,
AbstractSession session,
boolean isIsolated) |
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
buildReference(java.lang.Object object)
Allows subclass to create a SoftReference to the object.
|
CacheKey |
createCacheKey(java.lang.Object primaryKey,
java.lang.Object object,
java.lang.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(java.lang.Object reference)
Checks if the object is null, or reference's object is null.
|
CacheKey |
put(java.lang.Object primaryKey,
java.lang.Object object,
java.lang.Object writeLockValue,
long readTime)
Store the object in the cache at its primary key, and add to sub-cache list.
|
java.lang.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.
|
clone, collectLocks, elements, getCacheKey, getCacheKeys, getSize, getSize, keys, keys, lazyRelationshipLoaded, resetCacheKey
acquireDeferredLock, acquireLock, acquireLockNoWait, acquireLockWithWait, acquireReadLockOnCacheKey, acquireReadLockOnCacheKeyNoWait, containsKey, get, getAllCacheKeysFromIdentityMapWithEntityPK, getAllFromIdentityMapWithEntityPK, getCacheKeyForLock, getDefaultIdentityMapClass, getDescriptor, getDescriptorClass, getMaxSize, getWrapper, getWriteLockValue, release, remove, setDescriptor, setWrapper, setWriteLockValue, toString
public HardCacheWeakIdentityMap(int size, ClassDescriptor descriptor, AbstractSession session, boolean isIsolated)
public CacheKey createCacheKey(java.lang.Object primaryKey, java.lang.Object object, java.lang.Object writeLockValue, long readTime)
createCacheKey
in class WeakIdentityMap
public ExposedNodeLinkedList getReferenceCache()
public java.lang.Object buildReference(java.lang.Object object)
object
- is the domain object to cache.public boolean hasReference(java.lang.Object reference)
the
- object for hard or the reference for soft.public java.lang.Object remove(CacheKey cacheKey)
remove
in interface IdentityMap
remove
in class FullIdentityMap
public CacheKey put(java.lang.Object primaryKey, java.lang.Object object, java.lang.Object writeLockValue, long readTime)
put
in interface IdentityMap
put
in class FullIdentityMap
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.public void updateMaxSize(int maxSize)
updateMaxSize
in interface IdentityMap
updateMaxSize
in class AbstractIdentityMap
EclipseLink 2.6.3, "build v20160428-59c81c5" API Reference