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 |
|---|---|
| public class | HardCacheWeakIdentityMap.ReferenceCacheKey
Inner class to define the specialized weak cache key. |
| Modifier and Type | Field and Description |
|---|---|
| protected ExposedNodeLinkedList | referenceCache
A subset of cache entries have hard references maintained in this list to reduce garbage collection frequency |
| Access | Constructor and Description |
|---|---|
| public | HardCacheWeakIdentityMap(int size, ClassDescriptor descriptor, AbstractSession session, boolean isIsolated)
|
| Modifier and Type | Method and Description |
|---|---|
| public Object | buildReference(Object
is the domain object to cache. object)Allows subclass to create a SoftReference to the object. |
| public CacheKey | createCacheKey(Object primaryKey, Object object, Object writeLockValue, long readTime)
Overrides org. |
| public ExposedNodeLinkedList | |
| public boolean | hasReference(Object
the object for hard or the reference for soft. reference)Checks if the object is null, or reference's object is null. |
| public CacheKey | put(Object
is the primary key for the object. primaryKey, Object is the domain object to cache. object, Object is the current write lock value of object, if null the version is ignored. writeLockValue, long readTime)Overrides org. Implements org. |
| public Object | remove(CacheKey cacheKey)
Overrides org. Implements org. |
| public synchronized void | updateMaxSize(int maxSize)
Overrides org. Implements org. |
| referenceCache | back to summary |
|---|---|
| protected ExposedNodeLinkedList referenceCache A subset of cache entries have hard references maintained in this list to reduce garbage collection frequency | |
| HardCacheWeakIdentityMap | back to summary |
|---|---|
| public HardCacheWeakIdentityMap(int size, ClassDescriptor descriptor, AbstractSession session, boolean isIsolated) | |
| buildReference | back to summary |
|---|---|
| public Object buildReference(Object object) Allows subclass to create a SoftReference to the object.
| |
| createCacheKey | back to summary |
|---|---|
| public CacheKey createCacheKey(Object primaryKey, Object object, Object writeLockValue, long readTime) Overrides org. Use a ReferenceCacheKey that also stores the linked list node to manage the LRU sub-cache of references.
| |
| getReferenceCache | back to summary |
|---|---|
| public ExposedNodeLinkedList getReferenceCache() Return the linked reference cache. | |
| hasReference | back to summary |
|---|---|
| public boolean hasReference(Object reference) Checks if the object is null, or reference's object is null.
| |
| put | back to summary |
|---|---|
| public CacheKey put(Object primaryKey, Object object, Object writeLockValue, long readTime) Overrides org. Implements org. Store the object in the cache at its primary key, and add to sub-cache list.
| |
| remove | back to summary |
|---|---|
| public Object remove(CacheKey cacheKey) Overrides org. Implements org. Remove the cache key from the map and the sub-cache list.
| |
| updateMaxSize | back to summary |
|---|---|
| public synchronized void updateMaxSize(int maxSize) Overrides org. Implements org. This method will be used to update the max cache size.
| |
| Modifier and Type | Field and Description |
|---|---|
| protected LinkedNode |
| Access | Constructor and Description |
|---|---|
| public | ReferenceCacheKey(Object primaryKey, Object object, Object writeLockValue, long readTime, boolean isIsolated)
|
| Modifier and Type | Method and Description |
|---|---|
| public ExposedNodeLinkedList | |
| public LinkedNode | |
| public void | |
| public void | updateAccess()
Overrides org. |
| referenceNode | back to summary |
|---|---|
| protected LinkedNode referenceNode | |
| ReferenceCacheKey | back to summary |
|---|---|
| public ReferenceCacheKey(Object primaryKey, Object object, Object writeLockValue, long readTime, boolean isIsolated) | |
| getReferenceCache | back to summary |
|---|---|
| public ExposedNodeLinkedList getReferenceCache() | |
| getReferenceCacheNode | back to summary |
|---|---|
| public LinkedNode getReferenceCacheNode() | |
| setReferenceCacheNode | back to summary |
|---|---|
| public void setReferenceCacheNode(LinkedNode referenceNode) | |
| updateAccess | back to summary |
|---|---|
| public void updateAccess() Overrides org. Notifies that cache key that it has been accessed. Allows the LRU sub-cache to be maintained, the cache node must be moved to the front of the list.
| |