public class HardCacheWeakIdentityMap extends WeakIdentityMap
Purpose: A weak cache is identical to the weak identity map, however the weak 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 weak cache solves this through also holding a fixed number of objects is memory to improve caching. This makes used 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.
|
Modifier and Type | Field and Description |
---|---|
protected ExposedNodeLinkedList |
referenceCache |
cleanupCount, cleanupSize
cacheKeys
maxSize, searchKey
Constructor and Description |
---|
HardCacheWeakIdentityMap(int size) |
Modifier and Type | Method and Description |
---|---|
Object |
buildReference(Object object)
Creates a Soft reference if Required
|
CacheKey |
createCacheKey(Vector 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.
|
protected void |
put(CacheKey cacheKey)
Store the object in the cache with the cache key.
|
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.
|
cleanupDeadCacheKeys, getCleanupCount, getCleanupSize, setCleanupCount, setCleanupSize
clone, collectLocks, elements, getCacheKey, getCacheKeys, getSize, getSize, keys, put, resetCacheKey, resetCacheKey, setCacheKeys
acquireDeferredLock, acquireLock, acquireLockNoWait, acquireReadLockOnCacheKey, acquireReadLockOnCacheKeyNoWait, containsKey, createCacheKey, get, getCacheKey, getCacheKeyWithReadLock, getDefaultIdentityMapClass, getMaxSize, getSearchKey, getWrapper, getWriteLockValue, initialize, remove, setMaxSize, setSearchKey, setWrapper, setWriteLockValue, toString, updateCacheKey
protected ExposedNodeLinkedList referenceCache
public CacheKey createCacheKey(Vector primaryKey, Object object, Object writeLockValue, long readTime)
createCacheKey
in class WeakIdentityMap
public ExposedNodeLinkedList getReferenceCache()
public Object buildReference(Object object)
object
- is the domain object to cache.public boolean hasReference(Object reference)
the
- object for hard or the reference for soft.protected void put(CacheKey cacheKey)
put
in class WeakIdentityMap
public Object remove(CacheKey cacheKey)
remove
in class FullIdentityMap
public void updateMaxSize(int maxSize)
updateMaxSize
in class IdentityMap
Copyright © 2021. All rights reserved.